include/AT91/Atmel/lib_AT91SAM7X256.h
author Christian Taedcke <Christian.Taedcke@ica-traffic.de>
Fri, 19 Feb 2010 15:52:59 +0100
changeset 653 e2d0c5251fbd
parent 521 731bbe1b67b4
child 694 8dd1e58b3815
permissions -rw-r--r--
FIXED: - TimerInit() was missing
521
peter
parents:
diff changeset
     1
//* ----------------------------------------------------------------------------
peter
parents:
diff changeset
     2
//*         ATMEL Microcontroller Software Support  -  ROUSSET  -
peter
parents:
diff changeset
     3
//* ----------------------------------------------------------------------------
peter
parents:
diff changeset
     4
//* DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
peter
parents:
diff changeset
     5
//* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
peter
parents:
diff changeset
     6
//* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
peter
parents:
diff changeset
     7
//* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
peter
parents:
diff changeset
     8
//* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
peter
parents:
diff changeset
     9
//* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
peter
parents:
diff changeset
    10
//* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
peter
parents:
diff changeset
    11
//* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
peter
parents:
diff changeset
    12
//* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
peter
parents:
diff changeset
    13
//* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
peter
parents:
diff changeset
    14
//* ----------------------------------------------------------------------------
peter
parents:
diff changeset
    15
//* File Name           : lib_AT91SAM7X256.h
peter
parents:
diff changeset
    16
//* Object              : AT91SAM7X256 inlined functions
peter
parents:
diff changeset
    17
//* Generated           : AT91 SW Application Group  11/02/2005 (15:17:24)
peter
parents:
diff changeset
    18
//*
peter
parents:
diff changeset
    19
//* CVS Reference       : /lib_dbgu.h/1.1/Thu Aug 25 12:56:22 2005//
peter
parents:
diff changeset
    20
//* CVS Reference       : /lib_pmc_SAM7X.h/1.4/Tue Aug 30 13:00:36 2005//
peter
parents:
diff changeset
    21
//* CVS Reference       : /lib_VREG_6085B.h/1.1/Tue Feb  1 16:20:47 2005//
peter
parents:
diff changeset
    22
//* CVS Reference       : /lib_rstc_6098A.h/1.1/Wed Oct  6 10:39:20 2004//
peter
parents:
diff changeset
    23
//* CVS Reference       : /lib_ssc.h/1.4/Fri Jan 31 12:19:20 2003//
peter
parents:
diff changeset
    24
//* CVS Reference       : /lib_wdtc_6080A.h/1.1/Wed Oct  6 10:38:30 2004//
peter
parents:
diff changeset
    25
//* CVS Reference       : /lib_usart.h/1.5/Thu Nov 21 16:01:54 2002//
peter
parents:
diff changeset
    26
//* CVS Reference       : /lib_spi2.h/1.2/Tue Aug 23 15:37:28 2005//
peter
parents:
diff changeset
    27
//* CVS Reference       : /lib_pitc_6079A.h/1.2/Tue Nov  9 14:43:56 2004//
peter
parents:
diff changeset
    28
//* CVS Reference       : /lib_aic_6075b.h/1.2/Thu Jul  7 07:48:22 2005//
peter
parents:
diff changeset
    29
//* CVS Reference       : /lib_twi.h/1.3/Mon Jul 19 14:27:58 2004//
peter
parents:
diff changeset
    30
//* CVS Reference       : /lib_adc.h/1.6/Fri Oct 17 09:12:38 2003//
peter
parents:
diff changeset
    31
//* CVS Reference       : /lib_rttc_6081A.h/1.1/Wed Oct  6 10:39:38 2004//
peter
parents:
diff changeset
    32
//* CVS Reference       : /lib_udp.h/1.5/Tue Aug 30 12:13:47 2005//
peter
parents:
diff changeset
    33
//* CVS Reference       : /lib_tc_1753b.h/1.1/Fri Jan 31 12:20:02 2003//
peter
parents:
diff changeset
    34
//* CVS Reference       : /lib_MC_SAM7X.h/1.1/Thu Mar 25 15:19:14 2004//
peter
parents:
diff changeset
    35
//* CVS Reference       : /lib_pio.h/1.3/Fri Jan 31 12:18:56 2003//
peter
parents:
diff changeset
    36
//* CVS Reference       : /lib_can_AT91.h/1.5/Tue Aug 23 15:37:07 2005//
peter
parents:
diff changeset
    37
//* CVS Reference       : /lib_PWM_SAM.h/1.3/Thu Jan 22 10:10:50 2004//
peter
parents:
diff changeset
    38
//* CVS Reference       : /lib_pdc.h/1.2/Tue Jul  2 13:29:40 2002//
peter
parents:
diff changeset
    39
//* ----------------------------------------------------------------------------
peter
parents:
diff changeset
    40
peter
parents:
diff changeset
    41
#ifndef lib_AT91SAM7X256_H
peter
parents:
diff changeset
    42
#define lib_AT91SAM7X256_H
peter
parents:
diff changeset
    43
peter
parents:
diff changeset
    44
/* *****************************************************************************
peter
parents:
diff changeset
    45
                SOFTWARE API FOR AIC
peter
parents:
diff changeset
    46
   ***************************************************************************** */
peter
parents:
diff changeset
    47
#define AT91C_AIC_BRANCH_OPCODE ((void (*) ()) 0xE51FFF20) // ldr, pc, [pc, #-&F20]
peter
parents:
diff changeset
    48
peter
parents:
diff changeset
    49
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
    50
//* \fn    AT91F_AIC_ConfigureIt
peter
parents:
diff changeset
    51
//* \brief Interrupt Handler Initialization
peter
parents:
diff changeset
    52
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
    53
__inline unsigned int AT91F_AIC_ConfigureIt (
peter
parents:
diff changeset
    54
	AT91PS_AIC pAic,  // \arg pointer to the AIC registers
peter
parents:
diff changeset
    55
	unsigned int irq_id,     // \arg interrupt number to initialize
peter
parents:
diff changeset
    56
	unsigned int priority,   // \arg priority to give to the interrupt
peter
parents:
diff changeset
    57
	unsigned int src_type,   // \arg activation and sense of activation
peter
parents:
diff changeset
    58
	void (*newHandler) () ) // \arg address of the interrupt handler
peter
parents:
diff changeset
    59
{
peter
parents:
diff changeset
    60
	unsigned int oldHandler;
peter
parents:
diff changeset
    61
    unsigned int mask ;
peter
parents:
diff changeset
    62
peter
parents:
diff changeset
    63
    oldHandler = pAic->AIC_SVR[irq_id];
peter
parents:
diff changeset
    64
peter
parents:
diff changeset
    65
    mask = 0x1 << irq_id ;
peter
parents:
diff changeset
    66
    //* Disable the interrupt on the interrupt controller
peter
parents:
diff changeset
    67
    pAic->AIC_IDCR = mask ;
peter
parents:
diff changeset
    68
    //* Save the interrupt handler routine pointer and the interrupt priority
peter
parents:
diff changeset
    69
    pAic->AIC_SVR[irq_id] = (unsigned int) newHandler ;
peter
parents:
diff changeset
    70
    //* Store the Source Mode Register
peter
parents:
diff changeset
    71
    pAic->AIC_SMR[irq_id] = src_type | priority  ;
peter
parents:
diff changeset
    72
    //* Clear the interrupt on the interrupt controller
peter
parents:
diff changeset
    73
    pAic->AIC_ICCR = mask ;
peter
parents:
diff changeset
    74
peter
parents:
diff changeset
    75
	return oldHandler;
peter
parents:
diff changeset
    76
}
peter
parents:
diff changeset
    77
peter
parents:
diff changeset
    78
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
    79
//* \fn    AT91F_AIC_EnableIt
peter
parents:
diff changeset
    80
//* \brief Enable corresponding IT number
peter
parents:
diff changeset
    81
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
    82
__inline void AT91F_AIC_EnableIt (
peter
parents:
diff changeset
    83
	AT91PS_AIC pAic,      // \arg pointer to the AIC registers
peter
parents:
diff changeset
    84
	unsigned int irq_id ) // \arg interrupt number to initialize
peter
parents:
diff changeset
    85
{
peter
parents:
diff changeset
    86
    //* Enable the interrupt on the interrupt controller
peter
parents:
diff changeset
    87
    pAic->AIC_IECR = 0x1 << irq_id ;
peter
parents:
diff changeset
    88
}
peter
parents:
diff changeset
    89
peter
parents:
diff changeset
    90
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
    91
//* \fn    AT91F_AIC_DisableIt
peter
parents:
diff changeset
    92
//* \brief Disable corresponding IT number
peter
parents:
diff changeset
    93
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
    94
__inline void AT91F_AIC_DisableIt (
peter
parents:
diff changeset
    95
	AT91PS_AIC pAic,      // \arg pointer to the AIC registers
peter
parents:
diff changeset
    96
	unsigned int irq_id ) // \arg interrupt number to initialize
peter
parents:
diff changeset
    97
{
peter
parents:
diff changeset
    98
    unsigned int mask = 0x1 << irq_id;
peter
parents:
diff changeset
    99
    //* Disable the interrupt on the interrupt controller
peter
parents:
diff changeset
   100
    pAic->AIC_IDCR = mask ;
peter
parents:
diff changeset
   101
    //* Clear the interrupt on the Interrupt Controller ( if one is pending )
peter
parents:
diff changeset
   102
    pAic->AIC_ICCR = mask ;
peter
parents:
diff changeset
   103
}
peter
parents:
diff changeset
   104
peter
parents:
diff changeset
   105
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   106
//* \fn    AT91F_AIC_ClearIt
peter
parents:
diff changeset
   107
//* \brief Clear corresponding IT number
peter
parents:
diff changeset
   108
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   109
__inline void AT91F_AIC_ClearIt (
peter
parents:
diff changeset
   110
	AT91PS_AIC pAic,     // \arg pointer to the AIC registers
peter
parents:
diff changeset
   111
	unsigned int irq_id) // \arg interrupt number to initialize
peter
parents:
diff changeset
   112
{
peter
parents:
diff changeset
   113
    //* Clear the interrupt on the Interrupt Controller ( if one is pending )
peter
parents:
diff changeset
   114
    pAic->AIC_ICCR = (0x1 << irq_id);
peter
parents:
diff changeset
   115
}
peter
parents:
diff changeset
   116
peter
parents:
diff changeset
   117
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   118
//* \fn    AT91F_AIC_AcknowledgeIt
peter
parents:
diff changeset
   119
//* \brief Acknowledge corresponding IT number
peter
parents:
diff changeset
   120
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   121
__inline void AT91F_AIC_AcknowledgeIt (
peter
parents:
diff changeset
   122
	AT91PS_AIC pAic)     // \arg pointer to the AIC registers
peter
parents:
diff changeset
   123
{
peter
parents:
diff changeset
   124
    pAic->AIC_EOICR = pAic->AIC_EOICR;
peter
parents:
diff changeset
   125
}
peter
parents:
diff changeset
   126
peter
parents:
diff changeset
   127
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   128
//* \fn    AT91F_AIC_SetExceptionVector
peter
parents:
diff changeset
   129
//* \brief Configure vector handler
peter
parents:
diff changeset
   130
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   131
__inline unsigned int  AT91F_AIC_SetExceptionVector (
peter
parents:
diff changeset
   132
	unsigned int *pVector, // \arg pointer to the AIC registers
peter
parents:
diff changeset
   133
	void (*Handler) () )   // \arg Interrupt Handler
peter
parents:
diff changeset
   134
{
peter
parents:
diff changeset
   135
	unsigned int oldVector = *pVector;
peter
parents:
diff changeset
   136
peter
parents:
diff changeset
   137
	if ((unsigned int) Handler == (unsigned int) AT91C_AIC_BRANCH_OPCODE)
peter
parents:
diff changeset
   138
		*pVector = (unsigned int) AT91C_AIC_BRANCH_OPCODE;
peter
parents:
diff changeset
   139
	else
peter
parents:
diff changeset
   140
		*pVector = (((((unsigned int) Handler) - ((unsigned int) pVector) - 0x8) >> 2) & 0x00FFFFFF) | 0xEA000000;
peter
parents:
diff changeset
   141
peter
parents:
diff changeset
   142
	return oldVector;
peter
parents:
diff changeset
   143
}
peter
parents:
diff changeset
   144
peter
parents:
diff changeset
   145
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   146
//* \fn    AT91F_AIC_Trig
peter
parents:
diff changeset
   147
//* \brief Trig an IT
peter
parents:
diff changeset
   148
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   149
__inline void  AT91F_AIC_Trig (
peter
parents:
diff changeset
   150
	AT91PS_AIC pAic,     // \arg pointer to the AIC registers
peter
parents:
diff changeset
   151
	unsigned int irq_id) // \arg interrupt number
peter
parents:
diff changeset
   152
{
peter
parents:
diff changeset
   153
	pAic->AIC_ISCR = (0x1 << irq_id) ;
peter
parents:
diff changeset
   154
}
peter
parents:
diff changeset
   155
peter
parents:
diff changeset
   156
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   157
//* \fn    AT91F_AIC_IsActive
peter
parents:
diff changeset
   158
//* \brief Test if an IT is active
peter
parents:
diff changeset
   159
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   160
__inline unsigned int  AT91F_AIC_IsActive (
peter
parents:
diff changeset
   161
	AT91PS_AIC pAic,     // \arg pointer to the AIC registers
peter
parents:
diff changeset
   162
	unsigned int irq_id) // \arg Interrupt Number
peter
parents:
diff changeset
   163
{
peter
parents:
diff changeset
   164
	return (pAic->AIC_ISR & (0x1 << irq_id));
peter
parents:
diff changeset
   165
}
peter
parents:
diff changeset
   166
peter
parents:
diff changeset
   167
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   168
//* \fn    AT91F_AIC_IsPending
peter
parents:
diff changeset
   169
//* \brief Test if an IT is pending
peter
parents:
diff changeset
   170
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   171
__inline unsigned int  AT91F_AIC_IsPending (
peter
parents:
diff changeset
   172
	AT91PS_AIC pAic,     // \arg pointer to the AIC registers
peter
parents:
diff changeset
   173
	unsigned int irq_id) // \arg Interrupt Number
peter
parents:
diff changeset
   174
{
peter
parents:
diff changeset
   175
	return (pAic->AIC_IPR & (0x1 << irq_id));
peter
parents:
diff changeset
   176
}
peter
parents:
diff changeset
   177
peter
parents:
diff changeset
   178
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   179
//* \fn    AT91F_AIC_Open
peter
parents:
diff changeset
   180
//* \brief Set exception vectors and AIC registers to default values
peter
parents:
diff changeset
   181
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   182
__inline void AT91F_AIC_Open(
peter
parents:
diff changeset
   183
	AT91PS_AIC pAic,        // \arg pointer to the AIC registers
peter
parents:
diff changeset
   184
	void (*IrqHandler) (),  // \arg Default IRQ vector exception
peter
parents:
diff changeset
   185
	void (*FiqHandler) (),  // \arg Default FIQ vector exception
peter
parents:
diff changeset
   186
	void (*DefaultHandler)  (), // \arg Default Handler set in ISR
peter
parents:
diff changeset
   187
	void (*SpuriousHandler) (), // \arg Default Spurious Handler
peter
parents:
diff changeset
   188
	unsigned int protectMode)   // \arg Debug Control Register
peter
parents:
diff changeset
   189
{
peter
parents:
diff changeset
   190
	int i;
peter
parents:
diff changeset
   191
peter
parents:
diff changeset
   192
	// Disable all interrupts and set IVR to the default handler
peter
parents:
diff changeset
   193
	for (i = 0; i < 32; ++i) {
peter
parents:
diff changeset
   194
		AT91F_AIC_DisableIt(pAic, i);
peter
parents:
diff changeset
   195
		AT91F_AIC_ConfigureIt(pAic, i, AT91C_AIC_PRIOR_LOWEST, AT91C_AIC_SRCTYPE_HIGH_LEVEL, DefaultHandler);
peter
parents:
diff changeset
   196
	}
peter
parents:
diff changeset
   197
peter
parents:
diff changeset
   198
	// Set the IRQ exception vector
peter
parents:
diff changeset
   199
	AT91F_AIC_SetExceptionVector((unsigned int *) 0x18, IrqHandler);
peter
parents:
diff changeset
   200
	// Set the Fast Interrupt exception vector
peter
parents:
diff changeset
   201
	AT91F_AIC_SetExceptionVector((unsigned int *) 0x1C, FiqHandler);
peter
parents:
diff changeset
   202
peter
parents:
diff changeset
   203
	pAic->AIC_SPU = (unsigned int) SpuriousHandler;
peter
parents:
diff changeset
   204
	pAic->AIC_DCR = protectMode;
peter
parents:
diff changeset
   205
}
peter
parents:
diff changeset
   206
/* *****************************************************************************
peter
parents:
diff changeset
   207
                SOFTWARE API FOR PDC
peter
parents:
diff changeset
   208
   ***************************************************************************** */
peter
parents:
diff changeset
   209
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   210
//* \fn    AT91F_PDC_SetNextRx
peter
parents:
diff changeset
   211
//* \brief Set the next receive transfer descriptor
peter
parents:
diff changeset
   212
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   213
__inline void AT91F_PDC_SetNextRx (
peter
parents:
diff changeset
   214
	AT91PS_PDC pPDC,     // \arg pointer to a PDC controller
peter
parents:
diff changeset
   215
	char *address,       // \arg address to the next bloc to be received
peter
parents:
diff changeset
   216
	unsigned int bytes)  // \arg number of bytes to be received
peter
parents:
diff changeset
   217
{
peter
parents:
diff changeset
   218
	pPDC->PDC_RNPR = (unsigned int) address;
peter
parents:
diff changeset
   219
	pPDC->PDC_RNCR = bytes;
peter
parents:
diff changeset
   220
}
peter
parents:
diff changeset
   221
peter
parents:
diff changeset
   222
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   223
//* \fn    AT91F_PDC_SetNextTx
peter
parents:
diff changeset
   224
//* \brief Set the next transmit transfer descriptor
peter
parents:
diff changeset
   225
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   226
__inline void AT91F_PDC_SetNextTx (
peter
parents:
diff changeset
   227
	AT91PS_PDC pPDC,       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   228
	char *address,         // \arg address to the next bloc to be transmitted
peter
parents:
diff changeset
   229
	unsigned int bytes)    // \arg number of bytes to be transmitted
peter
parents:
diff changeset
   230
{
peter
parents:
diff changeset
   231
	pPDC->PDC_TNPR = (unsigned int) address;
peter
parents:
diff changeset
   232
	pPDC->PDC_TNCR = bytes;
peter
parents:
diff changeset
   233
}
peter
parents:
diff changeset
   234
peter
parents:
diff changeset
   235
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   236
//* \fn    AT91F_PDC_SetRx
peter
parents:
diff changeset
   237
//* \brief Set the receive transfer descriptor
peter
parents:
diff changeset
   238
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   239
__inline void AT91F_PDC_SetRx (
peter
parents:
diff changeset
   240
	AT91PS_PDC pPDC,       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   241
	char *address,         // \arg address to the next bloc to be received
peter
parents:
diff changeset
   242
	unsigned int bytes)    // \arg number of bytes to be received
peter
parents:
diff changeset
   243
{
peter
parents:
diff changeset
   244
	pPDC->PDC_RPR = (unsigned int) address;
peter
parents:
diff changeset
   245
	pPDC->PDC_RCR = bytes;
peter
parents:
diff changeset
   246
}
peter
parents:
diff changeset
   247
peter
parents:
diff changeset
   248
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   249
//* \fn    AT91F_PDC_SetTx
peter
parents:
diff changeset
   250
//* \brief Set the transmit transfer descriptor
peter
parents:
diff changeset
   251
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   252
__inline void AT91F_PDC_SetTx (
peter
parents:
diff changeset
   253
	AT91PS_PDC pPDC,       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   254
	char *address,         // \arg address to the next bloc to be transmitted
peter
parents:
diff changeset
   255
	unsigned int bytes)    // \arg number of bytes to be transmitted
peter
parents:
diff changeset
   256
{
peter
parents:
diff changeset
   257
	pPDC->PDC_TPR = (unsigned int) address;
peter
parents:
diff changeset
   258
	pPDC->PDC_TCR = bytes;
peter
parents:
diff changeset
   259
}
peter
parents:
diff changeset
   260
peter
parents:
diff changeset
   261
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   262
//* \fn    AT91F_PDC_EnableTx
peter
parents:
diff changeset
   263
//* \brief Enable transmit
peter
parents:
diff changeset
   264
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   265
__inline void AT91F_PDC_EnableTx (
peter
parents:
diff changeset
   266
	AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   267
{
peter
parents:
diff changeset
   268
	pPDC->PDC_PTCR = AT91C_PDC_TXTEN;
peter
parents:
diff changeset
   269
}
peter
parents:
diff changeset
   270
peter
parents:
diff changeset
   271
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   272
//* \fn    AT91F_PDC_EnableRx
peter
parents:
diff changeset
   273
//* \brief Enable receive
peter
parents:
diff changeset
   274
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   275
__inline void AT91F_PDC_EnableRx (
peter
parents:
diff changeset
   276
	AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   277
{
peter
parents:
diff changeset
   278
	pPDC->PDC_PTCR = AT91C_PDC_RXTEN;
peter
parents:
diff changeset
   279
}
peter
parents:
diff changeset
   280
peter
parents:
diff changeset
   281
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   282
//* \fn    AT91F_PDC_DisableTx
peter
parents:
diff changeset
   283
//* \brief Disable transmit
peter
parents:
diff changeset
   284
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   285
__inline void AT91F_PDC_DisableTx (
peter
parents:
diff changeset
   286
	AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   287
{
peter
parents:
diff changeset
   288
	pPDC->PDC_PTCR = AT91C_PDC_TXTDIS;
peter
parents:
diff changeset
   289
}
peter
parents:
diff changeset
   290
peter
parents:
diff changeset
   291
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   292
//* \fn    AT91F_PDC_DisableRx
peter
parents:
diff changeset
   293
//* \brief Disable receive
peter
parents:
diff changeset
   294
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   295
__inline void AT91F_PDC_DisableRx (
peter
parents:
diff changeset
   296
	AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   297
{
peter
parents:
diff changeset
   298
	pPDC->PDC_PTCR = AT91C_PDC_RXTDIS;
peter
parents:
diff changeset
   299
}
peter
parents:
diff changeset
   300
peter
parents:
diff changeset
   301
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   302
//* \fn    AT91F_PDC_IsTxEmpty
peter
parents:
diff changeset
   303
//* \brief Test if the current transfer descriptor has been sent
peter
parents:
diff changeset
   304
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   305
__inline int AT91F_PDC_IsTxEmpty ( // \return return 1 if transfer is complete
peter
parents:
diff changeset
   306
	AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   307
{
peter
parents:
diff changeset
   308
	return !(pPDC->PDC_TCR);
peter
parents:
diff changeset
   309
}
peter
parents:
diff changeset
   310
peter
parents:
diff changeset
   311
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   312
//* \fn    AT91F_PDC_IsNextTxEmpty
peter
parents:
diff changeset
   313
//* \brief Test if the next transfer descriptor has been moved to the current td
peter
parents:
diff changeset
   314
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   315
__inline int AT91F_PDC_IsNextTxEmpty ( // \return return 1 if transfer is complete
peter
parents:
diff changeset
   316
	AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   317
{
peter
parents:
diff changeset
   318
	return !(pPDC->PDC_TNCR);
peter
parents:
diff changeset
   319
}
peter
parents:
diff changeset
   320
peter
parents:
diff changeset
   321
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   322
//* \fn    AT91F_PDC_IsRxEmpty
peter
parents:
diff changeset
   323
//* \brief Test if the current transfer descriptor has been filled
peter
parents:
diff changeset
   324
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   325
__inline int AT91F_PDC_IsRxEmpty ( // \return return 1 if transfer is complete
peter
parents:
diff changeset
   326
	AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   327
{
peter
parents:
diff changeset
   328
	return !(pPDC->PDC_RCR);
peter
parents:
diff changeset
   329
}
peter
parents:
diff changeset
   330
peter
parents:
diff changeset
   331
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   332
//* \fn    AT91F_PDC_IsNextRxEmpty
peter
parents:
diff changeset
   333
//* \brief Test if the next transfer descriptor has been moved to the current td
peter
parents:
diff changeset
   334
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   335
__inline int AT91F_PDC_IsNextRxEmpty ( // \return return 1 if transfer is complete
peter
parents:
diff changeset
   336
	AT91PS_PDC pPDC )       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   337
{
peter
parents:
diff changeset
   338
	return !(pPDC->PDC_RNCR);
peter
parents:
diff changeset
   339
}
peter
parents:
diff changeset
   340
peter
parents:
diff changeset
   341
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   342
//* \fn    AT91F_PDC_Open
peter
parents:
diff changeset
   343
//* \brief Open PDC: disable TX and RX reset transfer descriptors, re-enable RX and TX
peter
parents:
diff changeset
   344
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   345
__inline void AT91F_PDC_Open (
peter
parents:
diff changeset
   346
	AT91PS_PDC pPDC)       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   347
{
peter
parents:
diff changeset
   348
    //* Disable the RX and TX PDC transfer requests
peter
parents:
diff changeset
   349
	AT91F_PDC_DisableRx(pPDC);
peter
parents:
diff changeset
   350
	AT91F_PDC_DisableTx(pPDC);
peter
parents:
diff changeset
   351
peter
parents:
diff changeset
   352
	//* Reset all Counter register Next buffer first
peter
parents:
diff changeset
   353
	AT91F_PDC_SetNextTx(pPDC, (char *) 0, 0);
peter
parents:
diff changeset
   354
	AT91F_PDC_SetNextRx(pPDC, (char *) 0, 0);
peter
parents:
diff changeset
   355
	AT91F_PDC_SetTx(pPDC, (char *) 0, 0);
peter
parents:
diff changeset
   356
	AT91F_PDC_SetRx(pPDC, (char *) 0, 0);
peter
parents:
diff changeset
   357
peter
parents:
diff changeset
   358
    //* Enable the RX and TX PDC transfer requests
peter
parents:
diff changeset
   359
	AT91F_PDC_EnableRx(pPDC);
peter
parents:
diff changeset
   360
	AT91F_PDC_EnableTx(pPDC);
peter
parents:
diff changeset
   361
}
peter
parents:
diff changeset
   362
peter
parents:
diff changeset
   363
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   364
//* \fn    AT91F_PDC_Close
peter
parents:
diff changeset
   365
//* \brief Close PDC: disable TX and RX reset transfer descriptors
peter
parents:
diff changeset
   366
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   367
__inline void AT91F_PDC_Close (
peter
parents:
diff changeset
   368
	AT91PS_PDC pPDC)       // \arg pointer to a PDC controller
peter
parents:
diff changeset
   369
{
peter
parents:
diff changeset
   370
    //* Disable the RX and TX PDC transfer requests
peter
parents:
diff changeset
   371
	AT91F_PDC_DisableRx(pPDC);
peter
parents:
diff changeset
   372
	AT91F_PDC_DisableTx(pPDC);
peter
parents:
diff changeset
   373
peter
parents:
diff changeset
   374
	//* Reset all Counter register Next buffer first
peter
parents:
diff changeset
   375
	AT91F_PDC_SetNextTx(pPDC, (char *) 0, 0);
peter
parents:
diff changeset
   376
	AT91F_PDC_SetNextRx(pPDC, (char *) 0, 0);
peter
parents:
diff changeset
   377
	AT91F_PDC_SetTx(pPDC, (char *) 0, 0);
peter
parents:
diff changeset
   378
	AT91F_PDC_SetRx(pPDC, (char *) 0, 0);
peter
parents:
diff changeset
   379
peter
parents:
diff changeset
   380
}
peter
parents:
diff changeset
   381
peter
parents:
diff changeset
   382
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   383
//* \fn    AT91F_PDC_SendFrame
peter
parents:
diff changeset
   384
//* \brief Close PDC: disable TX and RX reset transfer descriptors
peter
parents:
diff changeset
   385
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   386
__inline unsigned int AT91F_PDC_SendFrame(
peter
parents:
diff changeset
   387
	AT91PS_PDC pPDC,
peter
parents:
diff changeset
   388
	char *pBuffer,
peter
parents:
diff changeset
   389
	unsigned int szBuffer,
peter
parents:
diff changeset
   390
	char *pNextBuffer,
peter
parents:
diff changeset
   391
	unsigned int szNextBuffer )
peter
parents:
diff changeset
   392
{
peter
parents:
diff changeset
   393
	if (AT91F_PDC_IsTxEmpty(pPDC)) {
peter
parents:
diff changeset
   394
		//* Buffer and next buffer can be initialized
peter
parents:
diff changeset
   395
		AT91F_PDC_SetTx(pPDC, pBuffer, szBuffer);
peter
parents:
diff changeset
   396
		AT91F_PDC_SetNextTx(pPDC, pNextBuffer, szNextBuffer);
peter
parents:
diff changeset
   397
		return 2;
peter
parents:
diff changeset
   398
	}
peter
parents:
diff changeset
   399
	else if (AT91F_PDC_IsNextTxEmpty(pPDC)) {
peter
parents:
diff changeset
   400
		//* Only one buffer can be initialized
peter
parents:
diff changeset
   401
		AT91F_PDC_SetNextTx(pPDC, pBuffer, szBuffer);
peter
parents:
diff changeset
   402
		return 1;
peter
parents:
diff changeset
   403
	}
peter
parents:
diff changeset
   404
	else {
peter
parents:
diff changeset
   405
		//* All buffer are in use...
peter
parents:
diff changeset
   406
		return 0;
peter
parents:
diff changeset
   407
	}
peter
parents:
diff changeset
   408
}
peter
parents:
diff changeset
   409
peter
parents:
diff changeset
   410
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   411
//* \fn    AT91F_PDC_ReceiveFrame
peter
parents:
diff changeset
   412
//* \brief Close PDC: disable TX and RX reset transfer descriptors
peter
parents:
diff changeset
   413
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   414
__inline unsigned int AT91F_PDC_ReceiveFrame (
peter
parents:
diff changeset
   415
	AT91PS_PDC pPDC,
peter
parents:
diff changeset
   416
	char *pBuffer,
peter
parents:
diff changeset
   417
	unsigned int szBuffer,
peter
parents:
diff changeset
   418
	char *pNextBuffer,
peter
parents:
diff changeset
   419
	unsigned int szNextBuffer )
peter
parents:
diff changeset
   420
{
peter
parents:
diff changeset
   421
	if (AT91F_PDC_IsRxEmpty(pPDC)) {
peter
parents:
diff changeset
   422
		//* Buffer and next buffer can be initialized
peter
parents:
diff changeset
   423
		AT91F_PDC_SetRx(pPDC, pBuffer, szBuffer);
peter
parents:
diff changeset
   424
		AT91F_PDC_SetNextRx(pPDC, pNextBuffer, szNextBuffer);
peter
parents:
diff changeset
   425
		return 2;
peter
parents:
diff changeset
   426
	}
peter
parents:
diff changeset
   427
	else if (AT91F_PDC_IsNextRxEmpty(pPDC)) {
peter
parents:
diff changeset
   428
		//* Only one buffer can be initialized
peter
parents:
diff changeset
   429
		AT91F_PDC_SetNextRx(pPDC, pBuffer, szBuffer);
peter
parents:
diff changeset
   430
		return 1;
peter
parents:
diff changeset
   431
	}
peter
parents:
diff changeset
   432
	else {
peter
parents:
diff changeset
   433
		//* All buffer are in use...
peter
parents:
diff changeset
   434
		return 0;
peter
parents:
diff changeset
   435
	}
peter
parents:
diff changeset
   436
}
peter
parents:
diff changeset
   437
/* *****************************************************************************
peter
parents:
diff changeset
   438
                SOFTWARE API FOR DBGU
peter
parents:
diff changeset
   439
   ***************************************************************************** */
peter
parents:
diff changeset
   440
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   441
//* \fn    AT91F_DBGU_InterruptEnable
peter
parents:
diff changeset
   442
//* \brief Enable DBGU Interrupt
peter
parents:
diff changeset
   443
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   444
__inline void AT91F_DBGU_InterruptEnable(
peter
parents:
diff changeset
   445
        AT91PS_DBGU pDbgu,   // \arg  pointer to a DBGU controller
peter
parents:
diff changeset
   446
        unsigned int flag) // \arg  dbgu interrupt to be enabled
peter
parents:
diff changeset
   447
{
peter
parents:
diff changeset
   448
        pDbgu->DBGU_IER = flag;
peter
parents:
diff changeset
   449
}
peter
parents:
diff changeset
   450
peter
parents:
diff changeset
   451
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   452
//* \fn    AT91F_DBGU_InterruptDisable
peter
parents:
diff changeset
   453
//* \brief Disable DBGU Interrupt
peter
parents:
diff changeset
   454
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   455
__inline void AT91F_DBGU_InterruptDisable(
peter
parents:
diff changeset
   456
        AT91PS_DBGU pDbgu,   // \arg  pointer to a DBGU controller
peter
parents:
diff changeset
   457
        unsigned int flag) // \arg  dbgu interrupt to be disabled
peter
parents:
diff changeset
   458
{
peter
parents:
diff changeset
   459
        pDbgu->DBGU_IDR = flag;
peter
parents:
diff changeset
   460
}
peter
parents:
diff changeset
   461
peter
parents:
diff changeset
   462
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   463
//* \fn    AT91F_DBGU_GetInterruptMaskStatus
peter
parents:
diff changeset
   464
//* \brief Return DBGU Interrupt Mask Status
peter
parents:
diff changeset
   465
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   466
__inline unsigned int AT91F_DBGU_GetInterruptMaskStatus( // \return DBGU Interrupt Mask Status
peter
parents:
diff changeset
   467
        AT91PS_DBGU pDbgu) // \arg  pointer to a DBGU controller
peter
parents:
diff changeset
   468
{
peter
parents:
diff changeset
   469
        return pDbgu->DBGU_IMR;
peter
parents:
diff changeset
   470
}
peter
parents:
diff changeset
   471
peter
parents:
diff changeset
   472
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   473
//* \fn    AT91F_DBGU_IsInterruptMasked
peter
parents:
diff changeset
   474
//* \brief Test if DBGU Interrupt is Masked
peter
parents:
diff changeset
   475
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   476
__inline int AT91F_DBGU_IsInterruptMasked(
peter
parents:
diff changeset
   477
        AT91PS_DBGU pDbgu,   // \arg  pointer to a DBGU controller
peter
parents:
diff changeset
   478
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   479
{
peter
parents:
diff changeset
   480
        return (AT91F_DBGU_GetInterruptMaskStatus(pDbgu) & flag);
peter
parents:
diff changeset
   481
}
peter
parents:
diff changeset
   482
peter
parents:
diff changeset
   483
/* *****************************************************************************
peter
parents:
diff changeset
   484
                SOFTWARE API FOR PIO
peter
parents:
diff changeset
   485
   ***************************************************************************** */
peter
parents:
diff changeset
   486
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   487
//* \fn    AT91F_PIO_CfgPeriph
peter
parents:
diff changeset
   488
//* \brief Enable pins to be drived by peripheral
peter
parents:
diff changeset
   489
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   490
__inline void AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
   491
	AT91PS_PIO pPio,             // \arg pointer to a PIO controller
peter
parents:
diff changeset
   492
	unsigned int periphAEnable,  // \arg PERIPH A to enable
peter
parents:
diff changeset
   493
	unsigned int periphBEnable)  // \arg PERIPH B to enable
peter
parents:
diff changeset
   494
peter
parents:
diff changeset
   495
{
peter
parents:
diff changeset
   496
	pPio->PIO_ASR = periphAEnable;
peter
parents:
diff changeset
   497
	pPio->PIO_BSR = periphBEnable;
peter
parents:
diff changeset
   498
	pPio->PIO_PDR = (periphAEnable | periphBEnable); // Set in Periph mode
peter
parents:
diff changeset
   499
}
peter
parents:
diff changeset
   500
peter
parents:
diff changeset
   501
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   502
//* \fn    AT91F_PIO_CfgOutput
peter
parents:
diff changeset
   503
//* \brief Enable PIO in output mode
peter
parents:
diff changeset
   504
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   505
__inline void AT91F_PIO_CfgOutput(
peter
parents:
diff changeset
   506
	AT91PS_PIO pPio,             // \arg pointer to a PIO controller
peter
parents:
diff changeset
   507
	unsigned int pioEnable)      // \arg PIO to be enabled
peter
parents:
diff changeset
   508
{
peter
parents:
diff changeset
   509
	pPio->PIO_PER = pioEnable; // Set in PIO mode
peter
parents:
diff changeset
   510
	pPio->PIO_OER = pioEnable; // Configure in Output
peter
parents:
diff changeset
   511
}
peter
parents:
diff changeset
   512
peter
parents:
diff changeset
   513
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   514
//* \fn    AT91F_PIO_CfgInput
peter
parents:
diff changeset
   515
//* \brief Enable PIO in input mode
peter
parents:
diff changeset
   516
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   517
__inline void AT91F_PIO_CfgInput(
peter
parents:
diff changeset
   518
	AT91PS_PIO pPio,             // \arg pointer to a PIO controller
peter
parents:
diff changeset
   519
	unsigned int inputEnable)      // \arg PIO to be enabled
peter
parents:
diff changeset
   520
{
peter
parents:
diff changeset
   521
	// Disable output
peter
parents:
diff changeset
   522
	pPio->PIO_ODR  = inputEnable;
peter
parents:
diff changeset
   523
	pPio->PIO_PER  = inputEnable;
peter
parents:
diff changeset
   524
}
peter
parents:
diff changeset
   525
peter
parents:
diff changeset
   526
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   527
//* \fn    AT91F_PIO_CfgOpendrain
peter
parents:
diff changeset
   528
//* \brief Configure PIO in open drain
peter
parents:
diff changeset
   529
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   530
__inline void AT91F_PIO_CfgOpendrain(
peter
parents:
diff changeset
   531
	AT91PS_PIO pPio,             // \arg pointer to a PIO controller
peter
parents:
diff changeset
   532
	unsigned int multiDrvEnable) // \arg pio to be configured in open drain
peter
parents:
diff changeset
   533
{
peter
parents:
diff changeset
   534
	// Configure the multi-drive option
peter
parents:
diff changeset
   535
	pPio->PIO_MDDR = ~multiDrvEnable;
peter
parents:
diff changeset
   536
	pPio->PIO_MDER = multiDrvEnable;
peter
parents:
diff changeset
   537
}
peter
parents:
diff changeset
   538
peter
parents:
diff changeset
   539
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   540
//* \fn    AT91F_PIO_CfgPullup
peter
parents:
diff changeset
   541
//* \brief Enable pullup on PIO
peter
parents:
diff changeset
   542
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   543
__inline void AT91F_PIO_CfgPullup(
peter
parents:
diff changeset
   544
	AT91PS_PIO pPio,             // \arg pointer to a PIO controller
peter
parents:
diff changeset
   545
	unsigned int pullupEnable)   // \arg enable pullup on PIO
peter
parents:
diff changeset
   546
{
peter
parents:
diff changeset
   547
		// Connect or not Pullup
peter
parents:
diff changeset
   548
	pPio->PIO_PPUDR = ~pullupEnable;
peter
parents:
diff changeset
   549
	pPio->PIO_PPUER = pullupEnable;
peter
parents:
diff changeset
   550
}
peter
parents:
diff changeset
   551
peter
parents:
diff changeset
   552
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   553
//* \fn    AT91F_PIO_CfgDirectDrive
peter
parents:
diff changeset
   554
//* \brief Enable direct drive on PIO
peter
parents:
diff changeset
   555
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   556
__inline void AT91F_PIO_CfgDirectDrive(
peter
parents:
diff changeset
   557
	AT91PS_PIO pPio,             // \arg pointer to a PIO controller
peter
parents:
diff changeset
   558
	unsigned int directDrive)    // \arg PIO to be configured with direct drive
peter
parents:
diff changeset
   559
peter
parents:
diff changeset
   560
{
peter
parents:
diff changeset
   561
	// Configure the Direct Drive
peter
parents:
diff changeset
   562
	pPio->PIO_OWDR  = ~directDrive;
peter
parents:
diff changeset
   563
	pPio->PIO_OWER  = directDrive;
peter
parents:
diff changeset
   564
}
peter
parents:
diff changeset
   565
peter
parents:
diff changeset
   566
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   567
//* \fn    AT91F_PIO_CfgInputFilter
peter
parents:
diff changeset
   568
//* \brief Enable input filter on input PIO
peter
parents:
diff changeset
   569
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   570
__inline void AT91F_PIO_CfgInputFilter(
peter
parents:
diff changeset
   571
	AT91PS_PIO pPio,             // \arg pointer to a PIO controller
peter
parents:
diff changeset
   572
	unsigned int inputFilter)    // \arg PIO to be configured with input filter
peter
parents:
diff changeset
   573
peter
parents:
diff changeset
   574
{
peter
parents:
diff changeset
   575
	// Configure the Direct Drive
peter
parents:
diff changeset
   576
	pPio->PIO_IFDR  = ~inputFilter;
peter
parents:
diff changeset
   577
	pPio->PIO_IFER  = inputFilter;
peter
parents:
diff changeset
   578
}
peter
parents:
diff changeset
   579
peter
parents:
diff changeset
   580
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   581
//* \fn    AT91F_PIO_GetInput
peter
parents:
diff changeset
   582
//* \brief Return PIO input value
peter
parents:
diff changeset
   583
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   584
__inline unsigned int AT91F_PIO_GetInput( // \return PIO input
peter
parents:
diff changeset
   585
	AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   586
{
peter
parents:
diff changeset
   587
	return pPio->PIO_PDSR;
peter
parents:
diff changeset
   588
}
peter
parents:
diff changeset
   589
peter
parents:
diff changeset
   590
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   591
//* \fn    AT91F_PIO_IsInputSet
peter
parents:
diff changeset
   592
//* \brief Test if PIO is input flag is active
peter
parents:
diff changeset
   593
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   594
__inline int AT91F_PIO_IsInputSet(
peter
parents:
diff changeset
   595
	AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   596
	unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   597
{
peter
parents:
diff changeset
   598
	return (AT91F_PIO_GetInput(pPio) & flag);
peter
parents:
diff changeset
   599
}
peter
parents:
diff changeset
   600
peter
parents:
diff changeset
   601
peter
parents:
diff changeset
   602
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   603
//* \fn    AT91F_PIO_SetOutput
peter
parents:
diff changeset
   604
//* \brief Set to 1 output PIO
peter
parents:
diff changeset
   605
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   606
__inline void AT91F_PIO_SetOutput(
peter
parents:
diff changeset
   607
	AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   608
	unsigned int flag) // \arg  output to be set
peter
parents:
diff changeset
   609
{
peter
parents:
diff changeset
   610
	pPio->PIO_SODR = flag;
peter
parents:
diff changeset
   611
}
peter
parents:
diff changeset
   612
peter
parents:
diff changeset
   613
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   614
//* \fn    AT91F_PIO_ClearOutput
peter
parents:
diff changeset
   615
//* \brief Set to 0 output PIO
peter
parents:
diff changeset
   616
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   617
__inline void AT91F_PIO_ClearOutput(
peter
parents:
diff changeset
   618
	AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   619
	unsigned int flag) // \arg  output to be cleared
peter
parents:
diff changeset
   620
{
peter
parents:
diff changeset
   621
	pPio->PIO_CODR = flag;
peter
parents:
diff changeset
   622
}
peter
parents:
diff changeset
   623
peter
parents:
diff changeset
   624
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   625
//* \fn    AT91F_PIO_ForceOutput
peter
parents:
diff changeset
   626
//* \brief Force output when Direct drive option is enabled
peter
parents:
diff changeset
   627
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   628
__inline void AT91F_PIO_ForceOutput(
peter
parents:
diff changeset
   629
	AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   630
	unsigned int flag) // \arg  output to be forced
peter
parents:
diff changeset
   631
{
peter
parents:
diff changeset
   632
	pPio->PIO_ODSR = flag;
peter
parents:
diff changeset
   633
}
peter
parents:
diff changeset
   634
peter
parents:
diff changeset
   635
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   636
//* \fn    AT91F_PIO_Enable
peter
parents:
diff changeset
   637
//* \brief Enable PIO
peter
parents:
diff changeset
   638
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   639
__inline void AT91F_PIO_Enable(
peter
parents:
diff changeset
   640
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   641
        unsigned int flag) // \arg  pio to be enabled
peter
parents:
diff changeset
   642
{
peter
parents:
diff changeset
   643
        pPio->PIO_PER = flag;
peter
parents:
diff changeset
   644
}
peter
parents:
diff changeset
   645
peter
parents:
diff changeset
   646
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   647
//* \fn    AT91F_PIO_Disable
peter
parents:
diff changeset
   648
//* \brief Disable PIO
peter
parents:
diff changeset
   649
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   650
__inline void AT91F_PIO_Disable(
peter
parents:
diff changeset
   651
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   652
        unsigned int flag) // \arg  pio to be disabled
peter
parents:
diff changeset
   653
{
peter
parents:
diff changeset
   654
        pPio->PIO_PDR = flag;
peter
parents:
diff changeset
   655
}
peter
parents:
diff changeset
   656
peter
parents:
diff changeset
   657
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   658
//* \fn    AT91F_PIO_GetStatus
peter
parents:
diff changeset
   659
//* \brief Return PIO Status
peter
parents:
diff changeset
   660
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   661
__inline unsigned int AT91F_PIO_GetStatus( // \return PIO Status
peter
parents:
diff changeset
   662
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   663
{
peter
parents:
diff changeset
   664
        return pPio->PIO_PSR;
peter
parents:
diff changeset
   665
}
peter
parents:
diff changeset
   666
peter
parents:
diff changeset
   667
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   668
//* \fn    AT91F_PIO_IsSet
peter
parents:
diff changeset
   669
//* \brief Test if PIO is Set
peter
parents:
diff changeset
   670
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   671
__inline int AT91F_PIO_IsSet(
peter
parents:
diff changeset
   672
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   673
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   674
{
peter
parents:
diff changeset
   675
        return (AT91F_PIO_GetStatus(pPio) & flag);
peter
parents:
diff changeset
   676
}
peter
parents:
diff changeset
   677
peter
parents:
diff changeset
   678
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   679
//* \fn    AT91F_PIO_OutputEnable
peter
parents:
diff changeset
   680
//* \brief Output Enable PIO
peter
parents:
diff changeset
   681
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   682
__inline void AT91F_PIO_OutputEnable(
peter
parents:
diff changeset
   683
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   684
        unsigned int flag) // \arg  pio output to be enabled
peter
parents:
diff changeset
   685
{
peter
parents:
diff changeset
   686
        pPio->PIO_OER = flag;
peter
parents:
diff changeset
   687
}
peter
parents:
diff changeset
   688
peter
parents:
diff changeset
   689
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   690
//* \fn    AT91F_PIO_OutputDisable
peter
parents:
diff changeset
   691
//* \brief Output Enable PIO
peter
parents:
diff changeset
   692
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   693
__inline void AT91F_PIO_OutputDisable(
peter
parents:
diff changeset
   694
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   695
        unsigned int flag) // \arg  pio output to be disabled
peter
parents:
diff changeset
   696
{
peter
parents:
diff changeset
   697
        pPio->PIO_ODR = flag;
peter
parents:
diff changeset
   698
}
peter
parents:
diff changeset
   699
peter
parents:
diff changeset
   700
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   701
//* \fn    AT91F_PIO_GetOutputStatus
peter
parents:
diff changeset
   702
//* \brief Return PIO Output Status
peter
parents:
diff changeset
   703
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   704
__inline unsigned int AT91F_PIO_GetOutputStatus( // \return PIO Output Status
peter
parents:
diff changeset
   705
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   706
{
peter
parents:
diff changeset
   707
        return pPio->PIO_OSR;
peter
parents:
diff changeset
   708
}
peter
parents:
diff changeset
   709
peter
parents:
diff changeset
   710
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   711
//* \fn    AT91F_PIO_IsOuputSet
peter
parents:
diff changeset
   712
//* \brief Test if PIO Output is Set
peter
parents:
diff changeset
   713
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   714
__inline int AT91F_PIO_IsOutputSet(
peter
parents:
diff changeset
   715
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   716
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   717
{
peter
parents:
diff changeset
   718
        return (AT91F_PIO_GetOutputStatus(pPio) & flag);
peter
parents:
diff changeset
   719
}
peter
parents:
diff changeset
   720
peter
parents:
diff changeset
   721
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   722
//* \fn    AT91F_PIO_InputFilterEnable
peter
parents:
diff changeset
   723
//* \brief Input Filter Enable PIO
peter
parents:
diff changeset
   724
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   725
__inline void AT91F_PIO_InputFilterEnable(
peter
parents:
diff changeset
   726
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   727
        unsigned int flag) // \arg  pio input filter to be enabled
peter
parents:
diff changeset
   728
{
peter
parents:
diff changeset
   729
        pPio->PIO_IFER = flag;
peter
parents:
diff changeset
   730
}
peter
parents:
diff changeset
   731
peter
parents:
diff changeset
   732
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   733
//* \fn    AT91F_PIO_InputFilterDisable
peter
parents:
diff changeset
   734
//* \brief Input Filter Disable PIO
peter
parents:
diff changeset
   735
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   736
__inline void AT91F_PIO_InputFilterDisable(
peter
parents:
diff changeset
   737
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   738
        unsigned int flag) // \arg  pio input filter to be disabled
peter
parents:
diff changeset
   739
{
peter
parents:
diff changeset
   740
        pPio->PIO_IFDR = flag;
peter
parents:
diff changeset
   741
}
peter
parents:
diff changeset
   742
peter
parents:
diff changeset
   743
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   744
//* \fn    AT91F_PIO_GetInputFilterStatus
peter
parents:
diff changeset
   745
//* \brief Return PIO Input Filter Status
peter
parents:
diff changeset
   746
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   747
__inline unsigned int AT91F_PIO_GetInputFilterStatus( // \return PIO Input Filter Status
peter
parents:
diff changeset
   748
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   749
{
peter
parents:
diff changeset
   750
        return pPio->PIO_IFSR;
peter
parents:
diff changeset
   751
}
peter
parents:
diff changeset
   752
peter
parents:
diff changeset
   753
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   754
//* \fn    AT91F_PIO_IsInputFilterSet
peter
parents:
diff changeset
   755
//* \brief Test if PIO Input filter is Set
peter
parents:
diff changeset
   756
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   757
__inline int AT91F_PIO_IsInputFilterSet(
peter
parents:
diff changeset
   758
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   759
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   760
{
peter
parents:
diff changeset
   761
        return (AT91F_PIO_GetInputFilterStatus(pPio) & flag);
peter
parents:
diff changeset
   762
}
peter
parents:
diff changeset
   763
peter
parents:
diff changeset
   764
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   765
//* \fn    AT91F_PIO_GetOutputDataStatus
peter
parents:
diff changeset
   766
//* \brief Return PIO Output Data Status
peter
parents:
diff changeset
   767
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   768
__inline unsigned int AT91F_PIO_GetOutputDataStatus( // \return PIO Output Data Status
peter
parents:
diff changeset
   769
	AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   770
{
peter
parents:
diff changeset
   771
        return pPio->PIO_ODSR;
peter
parents:
diff changeset
   772
}
peter
parents:
diff changeset
   773
peter
parents:
diff changeset
   774
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   775
//* \fn    AT91F_PIO_InterruptEnable
peter
parents:
diff changeset
   776
//* \brief Enable PIO Interrupt
peter
parents:
diff changeset
   777
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   778
__inline void AT91F_PIO_InterruptEnable(
peter
parents:
diff changeset
   779
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   780
        unsigned int flag) // \arg  pio interrupt to be enabled
peter
parents:
diff changeset
   781
{
peter
parents:
diff changeset
   782
        pPio->PIO_IER = flag;
peter
parents:
diff changeset
   783
}
peter
parents:
diff changeset
   784
peter
parents:
diff changeset
   785
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   786
//* \fn    AT91F_PIO_InterruptDisable
peter
parents:
diff changeset
   787
//* \brief Disable PIO Interrupt
peter
parents:
diff changeset
   788
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   789
__inline void AT91F_PIO_InterruptDisable(
peter
parents:
diff changeset
   790
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   791
        unsigned int flag) // \arg  pio interrupt to be disabled
peter
parents:
diff changeset
   792
{
peter
parents:
diff changeset
   793
        pPio->PIO_IDR = flag;
peter
parents:
diff changeset
   794
}
peter
parents:
diff changeset
   795
peter
parents:
diff changeset
   796
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   797
//* \fn    AT91F_PIO_GetInterruptMaskStatus
peter
parents:
diff changeset
   798
//* \brief Return PIO Interrupt Mask Status
peter
parents:
diff changeset
   799
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   800
__inline unsigned int AT91F_PIO_GetInterruptMaskStatus( // \return PIO Interrupt Mask Status
peter
parents:
diff changeset
   801
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   802
{
peter
parents:
diff changeset
   803
        return pPio->PIO_IMR;
peter
parents:
diff changeset
   804
}
peter
parents:
diff changeset
   805
peter
parents:
diff changeset
   806
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   807
//* \fn    AT91F_PIO_GetInterruptStatus
peter
parents:
diff changeset
   808
//* \brief Return PIO Interrupt Status
peter
parents:
diff changeset
   809
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   810
__inline unsigned int AT91F_PIO_GetInterruptStatus( // \return PIO Interrupt Status
peter
parents:
diff changeset
   811
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   812
{
peter
parents:
diff changeset
   813
        return pPio->PIO_ISR;
peter
parents:
diff changeset
   814
}
peter
parents:
diff changeset
   815
peter
parents:
diff changeset
   816
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   817
//* \fn    AT91F_PIO_IsInterruptMasked
peter
parents:
diff changeset
   818
//* \brief Test if PIO Interrupt is Masked
peter
parents:
diff changeset
   819
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   820
__inline int AT91F_PIO_IsInterruptMasked(
peter
parents:
diff changeset
   821
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   822
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   823
{
peter
parents:
diff changeset
   824
        return (AT91F_PIO_GetInterruptMaskStatus(pPio) & flag);
peter
parents:
diff changeset
   825
}
peter
parents:
diff changeset
   826
peter
parents:
diff changeset
   827
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   828
//* \fn    AT91F_PIO_IsInterruptSet
peter
parents:
diff changeset
   829
//* \brief Test if PIO Interrupt is Set
peter
parents:
diff changeset
   830
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   831
__inline int AT91F_PIO_IsInterruptSet(
peter
parents:
diff changeset
   832
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   833
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   834
{
peter
parents:
diff changeset
   835
        return (AT91F_PIO_GetInterruptStatus(pPio) & flag);
peter
parents:
diff changeset
   836
}
peter
parents:
diff changeset
   837
peter
parents:
diff changeset
   838
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   839
//* \fn    AT91F_PIO_MultiDriverEnable
peter
parents:
diff changeset
   840
//* \brief Multi Driver Enable PIO
peter
parents:
diff changeset
   841
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   842
__inline void AT91F_PIO_MultiDriverEnable(
peter
parents:
diff changeset
   843
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   844
        unsigned int flag) // \arg  pio to be enabled
peter
parents:
diff changeset
   845
{
peter
parents:
diff changeset
   846
        pPio->PIO_MDER = flag;
peter
parents:
diff changeset
   847
}
peter
parents:
diff changeset
   848
peter
parents:
diff changeset
   849
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   850
//* \fn    AT91F_PIO_MultiDriverDisable
peter
parents:
diff changeset
   851
//* \brief Multi Driver Disable PIO
peter
parents:
diff changeset
   852
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   853
__inline void AT91F_PIO_MultiDriverDisable(
peter
parents:
diff changeset
   854
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   855
        unsigned int flag) // \arg  pio to be disabled
peter
parents:
diff changeset
   856
{
peter
parents:
diff changeset
   857
        pPio->PIO_MDDR = flag;
peter
parents:
diff changeset
   858
}
peter
parents:
diff changeset
   859
peter
parents:
diff changeset
   860
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   861
//* \fn    AT91F_PIO_GetMultiDriverStatus
peter
parents:
diff changeset
   862
//* \brief Return PIO Multi Driver Status
peter
parents:
diff changeset
   863
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   864
__inline unsigned int AT91F_PIO_GetMultiDriverStatus( // \return PIO Multi Driver Status
peter
parents:
diff changeset
   865
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   866
{
peter
parents:
diff changeset
   867
        return pPio->PIO_MDSR;
peter
parents:
diff changeset
   868
}
peter
parents:
diff changeset
   869
peter
parents:
diff changeset
   870
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   871
//* \fn    AT91F_PIO_IsMultiDriverSet
peter
parents:
diff changeset
   872
//* \brief Test if PIO MultiDriver is Set
peter
parents:
diff changeset
   873
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   874
__inline int AT91F_PIO_IsMultiDriverSet(
peter
parents:
diff changeset
   875
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   876
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   877
{
peter
parents:
diff changeset
   878
        return (AT91F_PIO_GetMultiDriverStatus(pPio) & flag);
peter
parents:
diff changeset
   879
}
peter
parents:
diff changeset
   880
peter
parents:
diff changeset
   881
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   882
//* \fn    AT91F_PIO_A_RegisterSelection
peter
parents:
diff changeset
   883
//* \brief PIO A Register Selection
peter
parents:
diff changeset
   884
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   885
__inline void AT91F_PIO_A_RegisterSelection(
peter
parents:
diff changeset
   886
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   887
        unsigned int flag) // \arg  pio A register selection
peter
parents:
diff changeset
   888
{
peter
parents:
diff changeset
   889
        pPio->PIO_ASR = flag;
peter
parents:
diff changeset
   890
}
peter
parents:
diff changeset
   891
peter
parents:
diff changeset
   892
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   893
//* \fn    AT91F_PIO_B_RegisterSelection
peter
parents:
diff changeset
   894
//* \brief PIO B Register Selection
peter
parents:
diff changeset
   895
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   896
__inline void AT91F_PIO_B_RegisterSelection(
peter
parents:
diff changeset
   897
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   898
        unsigned int flag) // \arg  pio B register selection
peter
parents:
diff changeset
   899
{
peter
parents:
diff changeset
   900
        pPio->PIO_BSR = flag;
peter
parents:
diff changeset
   901
}
peter
parents:
diff changeset
   902
peter
parents:
diff changeset
   903
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   904
//* \fn    AT91F_PIO_Get_AB_RegisterStatus
peter
parents:
diff changeset
   905
//* \brief Return PIO Interrupt Status
peter
parents:
diff changeset
   906
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   907
__inline unsigned int AT91F_PIO_Get_AB_RegisterStatus( // \return PIO AB Register Status
peter
parents:
diff changeset
   908
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   909
{
peter
parents:
diff changeset
   910
        return pPio->PIO_ABSR;
peter
parents:
diff changeset
   911
}
peter
parents:
diff changeset
   912
peter
parents:
diff changeset
   913
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   914
//* \fn    AT91F_PIO_IsAB_RegisterSet
peter
parents:
diff changeset
   915
//* \brief Test if PIO AB Register is Set
peter
parents:
diff changeset
   916
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   917
__inline int AT91F_PIO_IsAB_RegisterSet(
peter
parents:
diff changeset
   918
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   919
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   920
{
peter
parents:
diff changeset
   921
        return (AT91F_PIO_Get_AB_RegisterStatus(pPio) & flag);
peter
parents:
diff changeset
   922
}
peter
parents:
diff changeset
   923
peter
parents:
diff changeset
   924
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   925
//* \fn    AT91F_PIO_OutputWriteEnable
peter
parents:
diff changeset
   926
//* \brief Output Write Enable PIO
peter
parents:
diff changeset
   927
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   928
__inline void AT91F_PIO_OutputWriteEnable(
peter
parents:
diff changeset
   929
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   930
        unsigned int flag) // \arg  pio output write to be enabled
peter
parents:
diff changeset
   931
{
peter
parents:
diff changeset
   932
        pPio->PIO_OWER = flag;
peter
parents:
diff changeset
   933
}
peter
parents:
diff changeset
   934
peter
parents:
diff changeset
   935
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   936
//* \fn    AT91F_PIO_OutputWriteDisable
peter
parents:
diff changeset
   937
//* \brief Output Write Disable PIO
peter
parents:
diff changeset
   938
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   939
__inline void AT91F_PIO_OutputWriteDisable(
peter
parents:
diff changeset
   940
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   941
        unsigned int flag) // \arg  pio output write to be disabled
peter
parents:
diff changeset
   942
{
peter
parents:
diff changeset
   943
        pPio->PIO_OWDR = flag;
peter
parents:
diff changeset
   944
}
peter
parents:
diff changeset
   945
peter
parents:
diff changeset
   946
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   947
//* \fn    AT91F_PIO_GetOutputWriteStatus
peter
parents:
diff changeset
   948
//* \brief Return PIO Output Write Status
peter
parents:
diff changeset
   949
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   950
__inline unsigned int AT91F_PIO_GetOutputWriteStatus( // \return PIO Output Write Status
peter
parents:
diff changeset
   951
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   952
{
peter
parents:
diff changeset
   953
        return pPio->PIO_OWSR;
peter
parents:
diff changeset
   954
}
peter
parents:
diff changeset
   955
peter
parents:
diff changeset
   956
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   957
//* \fn    AT91F_PIO_IsOutputWriteSet
peter
parents:
diff changeset
   958
//* \brief Test if PIO OutputWrite is Set
peter
parents:
diff changeset
   959
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   960
__inline int AT91F_PIO_IsOutputWriteSet(
peter
parents:
diff changeset
   961
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   962
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   963
{
peter
parents:
diff changeset
   964
        return (AT91F_PIO_GetOutputWriteStatus(pPio) & flag);
peter
parents:
diff changeset
   965
}
peter
parents:
diff changeset
   966
peter
parents:
diff changeset
   967
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   968
//* \fn    AT91F_PIO_GetCfgPullup
peter
parents:
diff changeset
   969
//* \brief Return PIO Configuration Pullup
peter
parents:
diff changeset
   970
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   971
__inline unsigned int AT91F_PIO_GetCfgPullup( // \return PIO Configuration Pullup
peter
parents:
diff changeset
   972
        AT91PS_PIO pPio) // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   973
{
peter
parents:
diff changeset
   974
        return pPio->PIO_PPUSR;
peter
parents:
diff changeset
   975
}
peter
parents:
diff changeset
   976
peter
parents:
diff changeset
   977
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   978
//* \fn    AT91F_PIO_IsOutputDataStatusSet
peter
parents:
diff changeset
   979
//* \brief Test if PIO Output Data Status is Set
peter
parents:
diff changeset
   980
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   981
__inline int AT91F_PIO_IsOutputDataStatusSet(
peter
parents:
diff changeset
   982
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   983
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   984
{
peter
parents:
diff changeset
   985
        return (AT91F_PIO_GetOutputDataStatus(pPio) & flag);
peter
parents:
diff changeset
   986
}
peter
parents:
diff changeset
   987
peter
parents:
diff changeset
   988
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   989
//* \fn    AT91F_PIO_IsCfgPullupStatusSet
peter
parents:
diff changeset
   990
//* \brief Test if PIO Configuration Pullup Status is Set
peter
parents:
diff changeset
   991
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
   992
__inline int AT91F_PIO_IsCfgPullupStatusSet(
peter
parents:
diff changeset
   993
        AT91PS_PIO pPio,   // \arg  pointer to a PIO controller
peter
parents:
diff changeset
   994
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
   995
{
peter
parents:
diff changeset
   996
        return (~AT91F_PIO_GetCfgPullup(pPio) & flag);
peter
parents:
diff changeset
   997
}
peter
parents:
diff changeset
   998
peter
parents:
diff changeset
   999
/* *****************************************************************************
peter
parents:
diff changeset
  1000
                SOFTWARE API FOR PMC
peter
parents:
diff changeset
  1001
   ***************************************************************************** */
peter
parents:
diff changeset
  1002
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1003
//* \fn    AT91F_PMC_CfgSysClkEnableReg
peter
parents:
diff changeset
  1004
//* \brief Configure the System Clock Enable Register of the PMC controller
peter
parents:
diff changeset
  1005
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1006
__inline void AT91F_PMC_CfgSysClkEnableReg (
peter
parents:
diff changeset
  1007
	AT91PS_PMC pPMC, // \arg pointer to PMC controller
peter
parents:
diff changeset
  1008
	unsigned int mode)
peter
parents:
diff changeset
  1009
{
peter
parents:
diff changeset
  1010
	//* Write to the SCER register
peter
parents:
diff changeset
  1011
	pPMC->PMC_SCER = mode;
peter
parents:
diff changeset
  1012
}
peter
parents:
diff changeset
  1013
peter
parents:
diff changeset
  1014
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1015
//* \fn    AT91F_PMC_CfgSysClkDisableReg
peter
parents:
diff changeset
  1016
//* \brief Configure the System Clock Disable Register of the PMC controller
peter
parents:
diff changeset
  1017
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1018
__inline void AT91F_PMC_CfgSysClkDisableReg (
peter
parents:
diff changeset
  1019
	AT91PS_PMC pPMC, // \arg pointer to PMC controller
peter
parents:
diff changeset
  1020
	unsigned int mode)
peter
parents:
diff changeset
  1021
{
peter
parents:
diff changeset
  1022
	//* Write to the SCDR register
peter
parents:
diff changeset
  1023
	pPMC->PMC_SCDR = mode;
peter
parents:
diff changeset
  1024
}
peter
parents:
diff changeset
  1025
peter
parents:
diff changeset
  1026
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1027
//* \fn    AT91F_PMC_GetSysClkStatusReg
peter
parents:
diff changeset
  1028
//* \brief Return the System Clock Status Register of the PMC controller
peter
parents:
diff changeset
  1029
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1030
__inline unsigned int AT91F_PMC_GetSysClkStatusReg (
peter
parents:
diff changeset
  1031
	AT91PS_PMC pPMC // pointer to a CAN controller
peter
parents:
diff changeset
  1032
	)
peter
parents:
diff changeset
  1033
{
peter
parents:
diff changeset
  1034
	return pPMC->PMC_SCSR;
peter
parents:
diff changeset
  1035
}
peter
parents:
diff changeset
  1036
peter
parents:
diff changeset
  1037
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1038
//* \fn    AT91F_PMC_EnablePeriphClock
peter
parents:
diff changeset
  1039
//* \brief Enable peripheral clock
peter
parents:
diff changeset
  1040
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1041
__inline void AT91F_PMC_EnablePeriphClock (
peter
parents:
diff changeset
  1042
	AT91PS_PMC pPMC, // \arg pointer to PMC controller
peter
parents:
diff changeset
  1043
	unsigned int periphIds)  // \arg IDs of peripherals to enable
peter
parents:
diff changeset
  1044
{
peter
parents:
diff changeset
  1045
	pPMC->PMC_PCER = periphIds;
peter
parents:
diff changeset
  1046
}
peter
parents:
diff changeset
  1047
peter
parents:
diff changeset
  1048
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1049
//* \fn    AT91F_PMC_DisablePeriphClock
peter
parents:
diff changeset
  1050
//* \brief Disable peripheral clock
peter
parents:
diff changeset
  1051
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1052
__inline void AT91F_PMC_DisablePeriphClock (
peter
parents:
diff changeset
  1053
	AT91PS_PMC pPMC, // \arg pointer to PMC controller
peter
parents:
diff changeset
  1054
	unsigned int periphIds)  // \arg IDs of peripherals to enable
peter
parents:
diff changeset
  1055
{
peter
parents:
diff changeset
  1056
	pPMC->PMC_PCDR = periphIds;
peter
parents:
diff changeset
  1057
}
peter
parents:
diff changeset
  1058
peter
parents:
diff changeset
  1059
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1060
//* \fn    AT91F_PMC_GetPeriphClock
peter
parents:
diff changeset
  1061
//* \brief Get peripheral clock status
peter
parents:
diff changeset
  1062
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1063
__inline unsigned int AT91F_PMC_GetPeriphClock (
peter
parents:
diff changeset
  1064
	AT91PS_PMC pPMC) // \arg pointer to PMC controller
peter
parents:
diff changeset
  1065
{
peter
parents:
diff changeset
  1066
	return pPMC->PMC_PCSR;
peter
parents:
diff changeset
  1067
}
peter
parents:
diff changeset
  1068
peter
parents:
diff changeset
  1069
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1070
//* \fn    AT91F_CKGR_CfgMainOscillatorReg
peter
parents:
diff changeset
  1071
//* \brief Cfg the main oscillator
peter
parents:
diff changeset
  1072
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1073
__inline void AT91F_CKGR_CfgMainOscillatorReg (
peter
parents:
diff changeset
  1074
	AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1075
	unsigned int mode)
peter
parents:
diff changeset
  1076
{
peter
parents:
diff changeset
  1077
	pCKGR->CKGR_MOR = mode;
peter
parents:
diff changeset
  1078
}
peter
parents:
diff changeset
  1079
peter
parents:
diff changeset
  1080
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1081
//* \fn    AT91F_CKGR_GetMainOscillatorReg
peter
parents:
diff changeset
  1082
//* \brief Cfg the main oscillator
peter
parents:
diff changeset
  1083
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1084
__inline unsigned int AT91F_CKGR_GetMainOscillatorReg (
peter
parents:
diff changeset
  1085
	AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1086
{
peter
parents:
diff changeset
  1087
	return pCKGR->CKGR_MOR;
peter
parents:
diff changeset
  1088
}
peter
parents:
diff changeset
  1089
peter
parents:
diff changeset
  1090
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1091
//* \fn    AT91F_CKGR_EnableMainOscillator
peter
parents:
diff changeset
  1092
//* \brief Enable the main oscillator
peter
parents:
diff changeset
  1093
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1094
__inline void AT91F_CKGR_EnableMainOscillator(
peter
parents:
diff changeset
  1095
	AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1096
{
peter
parents:
diff changeset
  1097
	pCKGR->CKGR_MOR |= AT91C_CKGR_MOSCEN;
peter
parents:
diff changeset
  1098
}
peter
parents:
diff changeset
  1099
peter
parents:
diff changeset
  1100
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1101
//* \fn    AT91F_CKGR_DisableMainOscillator
peter
parents:
diff changeset
  1102
//* \brief Disable the main oscillator
peter
parents:
diff changeset
  1103
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1104
__inline void AT91F_CKGR_DisableMainOscillator (
peter
parents:
diff changeset
  1105
	AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1106
{
peter
parents:
diff changeset
  1107
	pCKGR->CKGR_MOR &= ~AT91C_CKGR_MOSCEN;
peter
parents:
diff changeset
  1108
}
peter
parents:
diff changeset
  1109
peter
parents:
diff changeset
  1110
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1111
//* \fn    AT91F_CKGR_CfgMainOscStartUpTime
peter
parents:
diff changeset
  1112
//* \brief Cfg MOR Register according to the main osc startup time
peter
parents:
diff changeset
  1113
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1114
__inline void AT91F_CKGR_CfgMainOscStartUpTime (
peter
parents:
diff changeset
  1115
	AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1116
	unsigned int startup_time,  // \arg main osc startup time in microsecond (us)
peter
parents:
diff changeset
  1117
	unsigned int slowClock)  // \arg slowClock in Hz
peter
parents:
diff changeset
  1118
{
peter
parents:
diff changeset
  1119
	pCKGR->CKGR_MOR &= ~AT91C_CKGR_OSCOUNT;
peter
parents:
diff changeset
  1120
	pCKGR->CKGR_MOR |= ((slowClock * startup_time)/(8*1000000)) << 8;
peter
parents:
diff changeset
  1121
}
peter
parents:
diff changeset
  1122
peter
parents:
diff changeset
  1123
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1124
//* \fn    AT91F_CKGR_GetMainClockFreqReg
peter
parents:
diff changeset
  1125
//* \brief Cfg the main oscillator
peter
parents:
diff changeset
  1126
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1127
__inline unsigned int AT91F_CKGR_GetMainClockFreqReg (
peter
parents:
diff changeset
  1128
	AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1129
{
peter
parents:
diff changeset
  1130
	return pCKGR->CKGR_MCFR;
peter
parents:
diff changeset
  1131
}
peter
parents:
diff changeset
  1132
peter
parents:
diff changeset
  1133
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1134
//* \fn    AT91F_CKGR_GetMainClock
peter
parents:
diff changeset
  1135
//* \brief Return Main clock in Hz
peter
parents:
diff changeset
  1136
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1137
__inline unsigned int AT91F_CKGR_GetMainClock (
peter
parents:
diff changeset
  1138
	AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1139
	unsigned int slowClock)  // \arg slowClock in Hz
peter
parents:
diff changeset
  1140
{
peter
parents:
diff changeset
  1141
	return ((pCKGR->CKGR_MCFR  & AT91C_CKGR_MAINF) * slowClock) >> 4;
peter
parents:
diff changeset
  1142
}
peter
parents:
diff changeset
  1143
peter
parents:
diff changeset
  1144
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1145
//* \fn    AT91F_PMC_CfgMCKReg
peter
parents:
diff changeset
  1146
//* \brief Cfg Master Clock Register
peter
parents:
diff changeset
  1147
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1148
__inline void AT91F_PMC_CfgMCKReg (
peter
parents:
diff changeset
  1149
	AT91PS_PMC pPMC, // \arg pointer to PMC controller
peter
parents:
diff changeset
  1150
	unsigned int mode)
peter
parents:
diff changeset
  1151
{
peter
parents:
diff changeset
  1152
	pPMC->PMC_MCKR = mode;
peter
parents:
diff changeset
  1153
}
peter
parents:
diff changeset
  1154
peter
parents:
diff changeset
  1155
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1156
//* \fn    AT91F_PMC_GetMCKReg
peter
parents:
diff changeset
  1157
//* \brief Return Master Clock Register
peter
parents:
diff changeset
  1158
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1159
__inline unsigned int AT91F_PMC_GetMCKReg(
peter
parents:
diff changeset
  1160
	AT91PS_PMC pPMC) // \arg pointer to PMC controller
peter
parents:
diff changeset
  1161
{
peter
parents:
diff changeset
  1162
	return pPMC->PMC_MCKR;
peter
parents:
diff changeset
  1163
}
peter
parents:
diff changeset
  1164
peter
parents:
diff changeset
  1165
//*------------------------------------------------------------------------------
peter
parents:
diff changeset
  1166
//* \fn    AT91F_PMC_GetMasterClock
peter
parents:
diff changeset
  1167
//* \brief Return master clock in Hz which correponds to processor clock for ARM7
peter
parents:
diff changeset
  1168
//*------------------------------------------------------------------------------
peter
parents:
diff changeset
  1169
__inline unsigned int AT91F_PMC_GetMasterClock (
peter
parents:
diff changeset
  1170
	AT91PS_PMC pPMC, // \arg pointer to PMC controller
peter
parents:
diff changeset
  1171
	AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1172
	unsigned int slowClock)  // \arg slowClock in Hz
peter
parents:
diff changeset
  1173
{
peter
parents:
diff changeset
  1174
	unsigned int reg = pPMC->PMC_MCKR;
peter
parents:
diff changeset
  1175
	unsigned int prescaler = (1 << ((reg & AT91C_PMC_PRES) >> 2));
peter
parents:
diff changeset
  1176
	unsigned int pllDivider, pllMultiplier;
peter
parents:
diff changeset
  1177
peter
parents:
diff changeset
  1178
	switch (reg & AT91C_PMC_CSS) {
peter
parents:
diff changeset
  1179
		case AT91C_PMC_CSS_SLOW_CLK: // Slow clock selected
peter
parents:
diff changeset
  1180
			return slowClock / prescaler;
peter
parents:
diff changeset
  1181
		case AT91C_PMC_CSS_MAIN_CLK: // Main clock is selected
peter
parents:
diff changeset
  1182
			return AT91F_CKGR_GetMainClock(pCKGR, slowClock) / prescaler;
peter
parents:
diff changeset
  1183
		case AT91C_PMC_CSS_PLL_CLK: // PLLB clock is selected
peter
parents:
diff changeset
  1184
			reg = pCKGR->CKGR_PLLR;
peter
parents:
diff changeset
  1185
			pllDivider    = (reg  & AT91C_CKGR_DIV);
peter
parents:
diff changeset
  1186
			pllMultiplier = ((reg  & AT91C_CKGR_MUL) >> 16) + 1;
peter
parents:
diff changeset
  1187
			return AT91F_CKGR_GetMainClock(pCKGR, slowClock) / pllDivider * pllMultiplier / prescaler;
peter
parents:
diff changeset
  1188
	}
peter
parents:
diff changeset
  1189
	return 0;
peter
parents:
diff changeset
  1190
}
peter
parents:
diff changeset
  1191
peter
parents:
diff changeset
  1192
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1193
//* \fn    AT91F_PMC_EnablePCK
peter
parents:
diff changeset
  1194
//* \brief Enable peripheral clock
peter
parents:
diff changeset
  1195
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1196
__inline void AT91F_PMC_EnablePCK (
peter
parents:
diff changeset
  1197
	AT91PS_PMC pPMC, // \arg pointer to PMC controller
peter
parents:
diff changeset
  1198
	unsigned int pck,  // \arg Peripheral clock identifier 0 .. 7
peter
parents:
diff changeset
  1199
	unsigned int mode)
peter
parents:
diff changeset
  1200
{
peter
parents:
diff changeset
  1201
	pPMC->PMC_PCKR[pck] = mode;
peter
parents:
diff changeset
  1202
	pPMC->PMC_SCER = (1 << pck) << 8;
peter
parents:
diff changeset
  1203
}
peter
parents:
diff changeset
  1204
peter
parents:
diff changeset
  1205
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1206
//* \fn    AT91F_PMC_DisablePCK
peter
parents:
diff changeset
  1207
//* \brief Enable peripheral clock
peter
parents:
diff changeset
  1208
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1209
__inline void AT91F_PMC_DisablePCK (
peter
parents:
diff changeset
  1210
	AT91PS_PMC pPMC, // \arg pointer to PMC controller
peter
parents:
diff changeset
  1211
	unsigned int pck)  // \arg Peripheral clock identifier 0 .. 7
peter
parents:
diff changeset
  1212
{
peter
parents:
diff changeset
  1213
	pPMC->PMC_SCDR = (1 << pck) << 8;
peter
parents:
diff changeset
  1214
}
peter
parents:
diff changeset
  1215
peter
parents:
diff changeset
  1216
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1217
//* \fn    AT91F_PMC_EnableIt
peter
parents:
diff changeset
  1218
//* \brief Enable PMC interrupt
peter
parents:
diff changeset
  1219
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1220
__inline void AT91F_PMC_EnableIt (
peter
parents:
diff changeset
  1221
	AT91PS_PMC pPMC,     // pointer to a PMC controller
peter
parents:
diff changeset
  1222
	unsigned int flag)   // IT to be enabled
peter
parents:
diff changeset
  1223
{
peter
parents:
diff changeset
  1224
	//* Write to the IER register
peter
parents:
diff changeset
  1225
	pPMC->PMC_IER = flag;
peter
parents:
diff changeset
  1226
}
peter
parents:
diff changeset
  1227
peter
parents:
diff changeset
  1228
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1229
//* \fn    AT91F_PMC_DisableIt
peter
parents:
diff changeset
  1230
//* \brief Disable PMC interrupt
peter
parents:
diff changeset
  1231
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1232
__inline void AT91F_PMC_DisableIt (
peter
parents:
diff changeset
  1233
	AT91PS_PMC pPMC, // pointer to a PMC controller
peter
parents:
diff changeset
  1234
	unsigned int flag) // IT to be disabled
peter
parents:
diff changeset
  1235
{
peter
parents:
diff changeset
  1236
	//* Write to the IDR register
peter
parents:
diff changeset
  1237
	pPMC->PMC_IDR = flag;
peter
parents:
diff changeset
  1238
}
peter
parents:
diff changeset
  1239
peter
parents:
diff changeset
  1240
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1241
//* \fn    AT91F_PMC_GetStatus
peter
parents:
diff changeset
  1242
//* \brief Return PMC Interrupt Status
peter
parents:
diff changeset
  1243
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1244
__inline unsigned int AT91F_PMC_GetStatus( // \return PMC Interrupt Status
peter
parents:
diff changeset
  1245
	AT91PS_PMC pPMC) // pointer to a PMC controller
peter
parents:
diff changeset
  1246
{
peter
parents:
diff changeset
  1247
	return pPMC->PMC_SR;
peter
parents:
diff changeset
  1248
}
peter
parents:
diff changeset
  1249
peter
parents:
diff changeset
  1250
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1251
//* \fn    AT91F_PMC_GetInterruptMaskStatus
peter
parents:
diff changeset
  1252
//* \brief Return PMC Interrupt Mask Status
peter
parents:
diff changeset
  1253
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1254
__inline unsigned int AT91F_PMC_GetInterruptMaskStatus( // \return PMC Interrupt Mask Status
peter
parents:
diff changeset
  1255
	AT91PS_PMC pPMC) // pointer to a PMC controller
peter
parents:
diff changeset
  1256
{
peter
parents:
diff changeset
  1257
	return pPMC->PMC_IMR;
peter
parents:
diff changeset
  1258
}
peter
parents:
diff changeset
  1259
peter
parents:
diff changeset
  1260
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1261
//* \fn    AT91F_PMC_IsInterruptMasked
peter
parents:
diff changeset
  1262
//* \brief Test if PMC Interrupt is Masked
peter
parents:
diff changeset
  1263
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1264
__inline unsigned int AT91F_PMC_IsInterruptMasked(
peter
parents:
diff changeset
  1265
        AT91PS_PMC pPMC,   // \arg  pointer to a PMC controller
peter
parents:
diff changeset
  1266
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  1267
{
peter
parents:
diff changeset
  1268
	return (AT91F_PMC_GetInterruptMaskStatus(pPMC) & flag);
peter
parents:
diff changeset
  1269
}
peter
parents:
diff changeset
  1270
peter
parents:
diff changeset
  1271
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1272
//* \fn    AT91F_PMC_IsStatusSet
peter
parents:
diff changeset
  1273
//* \brief Test if PMC Status is Set
peter
parents:
diff changeset
  1274
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1275
__inline unsigned int AT91F_PMC_IsStatusSet(
peter
parents:
diff changeset
  1276
        AT91PS_PMC pPMC,   // \arg  pointer to a PMC controller
peter
parents:
diff changeset
  1277
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  1278
{
peter
parents:
diff changeset
  1279
	return (AT91F_PMC_GetStatus(pPMC) & flag);
peter
parents:
diff changeset
  1280
}
peter
parents:
diff changeset
  1281
peter
parents:
diff changeset
  1282
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  1283
//  \fn    AT91F_CKGR_CfgPLLReg
peter
parents:
diff changeset
  1284
//  \brief Cfg the PLL Register
peter
parents:
diff changeset
  1285
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  1286
__inline void AT91F_CKGR_CfgPLLReg (
peter
parents:
diff changeset
  1287
	AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1288
	unsigned int mode)
peter
parents:
diff changeset
  1289
{
peter
parents:
diff changeset
  1290
	pCKGR->CKGR_PLLR = mode;
peter
parents:
diff changeset
  1291
}
peter
parents:
diff changeset
  1292
peter
parents:
diff changeset
  1293
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  1294
//  \fn    AT91F_CKGR_GetPLLReg
peter
parents:
diff changeset
  1295
//  \brief Get the PLL Register
peter
parents:
diff changeset
  1296
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  1297
__inline unsigned int AT91F_CKGR_GetPLLReg (
peter
parents:
diff changeset
  1298
	AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
peter
parents:
diff changeset
  1299
{
peter
parents:
diff changeset
  1300
	return pCKGR->CKGR_PLLR;
peter
parents:
diff changeset
  1301
}
peter
parents:
diff changeset
  1302
peter
parents:
diff changeset
  1303
peter
parents:
diff changeset
  1304
/* *****************************************************************************
peter
parents:
diff changeset
  1305
                SOFTWARE API FOR RSTC
peter
parents:
diff changeset
  1306
   ***************************************************************************** */
peter
parents:
diff changeset
  1307
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1308
//* \fn    AT91F_RSTSoftReset
peter
parents:
diff changeset
  1309
//* \brief Start Software Reset
peter
parents:
diff changeset
  1310
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1311
__inline void AT91F_RSTSoftReset(
peter
parents:
diff changeset
  1312
        AT91PS_RSTC pRSTC,
peter
parents:
diff changeset
  1313
        unsigned int reset)
peter
parents:
diff changeset
  1314
{
peter
parents:
diff changeset
  1315
	pRSTC->RSTC_RCR = (0xA5000000 | reset);
peter
parents:
diff changeset
  1316
}
peter
parents:
diff changeset
  1317
peter
parents:
diff changeset
  1318
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1319
//* \fn    AT91F_RSTSetMode
peter
parents:
diff changeset
  1320
//* \brief Set Reset Mode
peter
parents:
diff changeset
  1321
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1322
__inline void AT91F_RSTSetMode(
peter
parents:
diff changeset
  1323
        AT91PS_RSTC pRSTC,
peter
parents:
diff changeset
  1324
        unsigned int mode)
peter
parents:
diff changeset
  1325
{
peter
parents:
diff changeset
  1326
	pRSTC->RSTC_RMR = (0xA5000000 | mode);
peter
parents:
diff changeset
  1327
}
peter
parents:
diff changeset
  1328
peter
parents:
diff changeset
  1329
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1330
//* \fn    AT91F_RSTGetMode
peter
parents:
diff changeset
  1331
//* \brief Get Reset Mode
peter
parents:
diff changeset
  1332
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1333
__inline unsigned int AT91F_RSTGetMode(
peter
parents:
diff changeset
  1334
        AT91PS_RSTC pRSTC)
peter
parents:
diff changeset
  1335
{
peter
parents:
diff changeset
  1336
	return (pRSTC->RSTC_RMR);
peter
parents:
diff changeset
  1337
}
peter
parents:
diff changeset
  1338
peter
parents:
diff changeset
  1339
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1340
//* \fn    AT91F_RSTGetStatus
peter
parents:
diff changeset
  1341
//* \brief Get Reset Status
peter
parents:
diff changeset
  1342
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1343
__inline unsigned int AT91F_RSTGetStatus(
peter
parents:
diff changeset
  1344
        AT91PS_RSTC pRSTC)
peter
parents:
diff changeset
  1345
{
peter
parents:
diff changeset
  1346
	return (pRSTC->RSTC_RSR);
peter
parents:
diff changeset
  1347
}
peter
parents:
diff changeset
  1348
peter
parents:
diff changeset
  1349
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1350
//* \fn    AT91F_RSTIsSoftRstActive
peter
parents:
diff changeset
  1351
//* \brief Return !=0 if software reset is still not completed
peter
parents:
diff changeset
  1352
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1353
__inline unsigned int AT91F_RSTIsSoftRstActive(
peter
parents:
diff changeset
  1354
        AT91PS_RSTC pRSTC)
peter
parents:
diff changeset
  1355
{
peter
parents:
diff changeset
  1356
	return ((pRSTC->RSTC_RSR) & AT91C_RSTC_SRCMP);
peter
parents:
diff changeset
  1357
}
peter
parents:
diff changeset
  1358
/* *****************************************************************************
peter
parents:
diff changeset
  1359
                SOFTWARE API FOR RTTC
peter
parents:
diff changeset
  1360
   ***************************************************************************** */
peter
parents:
diff changeset
  1361
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1362
//* \fn     AT91F_SetRTT_TimeBase()
peter
parents:
diff changeset
  1363
//* \brief  Set the RTT prescaler according to the TimeBase in ms
peter
parents:
diff changeset
  1364
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1365
__inline unsigned int AT91F_RTTSetTimeBase(
peter
parents:
diff changeset
  1366
        AT91PS_RTTC pRTTC,
peter
parents:
diff changeset
  1367
        unsigned int ms)
peter
parents:
diff changeset
  1368
{
peter
parents:
diff changeset
  1369
	if (ms > 2000)
peter
parents:
diff changeset
  1370
		return 1;   // AT91C_TIME_OUT_OF_RANGE
peter
parents:
diff changeset
  1371
	pRTTC->RTTC_RTMR &= ~0xFFFF;	
peter
parents:
diff changeset
  1372
	pRTTC->RTTC_RTMR |= (((ms << 15) /1000) & 0xFFFF);	
peter
parents:
diff changeset
  1373
	return 0;
peter
parents:
diff changeset
  1374
}
peter
parents:
diff changeset
  1375
peter
parents:
diff changeset
  1376
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1377
//* \fn     AT91F_RTTSetPrescaler()
peter
parents:
diff changeset
  1378
//* \brief  Set the new prescaler value
peter
parents:
diff changeset
  1379
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1380
__inline unsigned int AT91F_RTTSetPrescaler(
peter
parents:
diff changeset
  1381
        AT91PS_RTTC pRTTC,
peter
parents:
diff changeset
  1382
        unsigned int rtpres)
peter
parents:
diff changeset
  1383
{
peter
parents:
diff changeset
  1384
	pRTTC->RTTC_RTMR &= ~0xFFFF;	
peter
parents:
diff changeset
  1385
	pRTTC->RTTC_RTMR |= (rtpres & 0xFFFF);	
peter
parents:
diff changeset
  1386
	return (pRTTC->RTTC_RTMR);
peter
parents:
diff changeset
  1387
}
peter
parents:
diff changeset
  1388
peter
parents:
diff changeset
  1389
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1390
//* \fn     AT91F_RTTRestart()
peter
parents:
diff changeset
  1391
//* \brief  Restart the RTT prescaler
peter
parents:
diff changeset
  1392
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1393
__inline void AT91F_RTTRestart(
peter
parents:
diff changeset
  1394
        AT91PS_RTTC pRTTC)
peter
parents:
diff changeset
  1395
{
peter
parents:
diff changeset
  1396
	pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTRST;	
peter
parents:
diff changeset
  1397
}
peter
parents:
diff changeset
  1398
peter
parents:
diff changeset
  1399
peter
parents:
diff changeset
  1400
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1401
//* \fn     AT91F_RTT_SetAlarmINT()
peter
parents:
diff changeset
  1402
//* \brief  Enable RTT Alarm Interrupt
peter
parents:
diff changeset
  1403
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1404
__inline void AT91F_RTTSetAlarmINT(
peter
parents:
diff changeset
  1405
        AT91PS_RTTC pRTTC)
peter
parents:
diff changeset
  1406
{
peter
parents:
diff changeset
  1407
	pRTTC->RTTC_RTMR |= AT91C_RTTC_ALMIEN;
peter
parents:
diff changeset
  1408
}
peter
parents:
diff changeset
  1409
peter
parents:
diff changeset
  1410
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1411
//* \fn     AT91F_RTT_ClearAlarmINT()
peter
parents:
diff changeset
  1412
//* \brief  Disable RTT Alarm Interrupt
peter
parents:
diff changeset
  1413
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1414
__inline void AT91F_RTTClearAlarmINT(
peter
parents:
diff changeset
  1415
        AT91PS_RTTC pRTTC)
peter
parents:
diff changeset
  1416
{
peter
parents:
diff changeset
  1417
	pRTTC->RTTC_RTMR &= ~AT91C_RTTC_ALMIEN;
peter
parents:
diff changeset
  1418
}
peter
parents:
diff changeset
  1419
peter
parents:
diff changeset
  1420
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1421
//* \fn     AT91F_RTT_SetRttIncINT()
peter
parents:
diff changeset
  1422
//* \brief  Enable RTT INC Interrupt
peter
parents:
diff changeset
  1423
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1424
__inline void AT91F_RTTSetRttIncINT(
peter
parents:
diff changeset
  1425
        AT91PS_RTTC pRTTC)
peter
parents:
diff changeset
  1426
{
peter
parents:
diff changeset
  1427
	pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTINCIEN;
peter
parents:
diff changeset
  1428
}
peter
parents:
diff changeset
  1429
peter
parents:
diff changeset
  1430
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1431
//* \fn     AT91F_RTT_ClearRttIncINT()
peter
parents:
diff changeset
  1432
//* \brief  Disable RTT INC Interrupt
peter
parents:
diff changeset
  1433
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1434
__inline void AT91F_RTTClearRttIncINT(
peter
parents:
diff changeset
  1435
        AT91PS_RTTC pRTTC)
peter
parents:
diff changeset
  1436
{
peter
parents:
diff changeset
  1437
	pRTTC->RTTC_RTMR &= ~AT91C_RTTC_RTTINCIEN;
peter
parents:
diff changeset
  1438
}
peter
parents:
diff changeset
  1439
peter
parents:
diff changeset
  1440
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1441
//* \fn     AT91F_RTT_SetAlarmValue()
peter
parents:
diff changeset
  1442
//* \brief  Set RTT Alarm Value
peter
parents:
diff changeset
  1443
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1444
__inline void AT91F_RTTSetAlarmValue(
peter
parents:
diff changeset
  1445
        AT91PS_RTTC pRTTC, unsigned int alarm)
peter
parents:
diff changeset
  1446
{
peter
parents:
diff changeset
  1447
	pRTTC->RTTC_RTAR = alarm;
peter
parents:
diff changeset
  1448
}
peter
parents:
diff changeset
  1449
peter
parents:
diff changeset
  1450
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1451
//* \fn     AT91F_RTT_GetAlarmValue()
peter
parents:
diff changeset
  1452
//* \brief  Get RTT Alarm Value
peter
parents:
diff changeset
  1453
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1454
__inline unsigned int AT91F_RTTGetAlarmValue(
peter
parents:
diff changeset
  1455
        AT91PS_RTTC pRTTC)
peter
parents:
diff changeset
  1456
{
peter
parents:
diff changeset
  1457
	return(pRTTC->RTTC_RTAR);
peter
parents:
diff changeset
  1458
}
peter
parents:
diff changeset
  1459
peter
parents:
diff changeset
  1460
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1461
//* \fn     AT91F_RTTGetStatus()
peter
parents:
diff changeset
  1462
//* \brief  Read the RTT status
peter
parents:
diff changeset
  1463
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1464
__inline unsigned int AT91F_RTTGetStatus(
peter
parents:
diff changeset
  1465
        AT91PS_RTTC pRTTC)
peter
parents:
diff changeset
  1466
{
peter
parents:
diff changeset
  1467
	return(pRTTC->RTTC_RTSR);
peter
parents:
diff changeset
  1468
}
peter
parents:
diff changeset
  1469
peter
parents:
diff changeset
  1470
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1471
//* \fn     AT91F_RTT_ReadValue()
peter
parents:
diff changeset
  1472
//* \brief  Read the RTT value
peter
parents:
diff changeset
  1473
//*--------------------------------------------------------------------------------------
peter
parents:
diff changeset
  1474
__inline unsigned int AT91F_RTTReadValue(
peter
parents:
diff changeset
  1475
        AT91PS_RTTC pRTTC)
peter
parents:
diff changeset
  1476
{
peter
parents:
diff changeset
  1477
        register volatile unsigned int val1,val2;
peter
parents:
diff changeset
  1478
	do
peter
parents:
diff changeset
  1479
	{
peter
parents:
diff changeset
  1480
		val1 = pRTTC->RTTC_RTVR;
peter
parents:
diff changeset
  1481
		val2 = pRTTC->RTTC_RTVR;
peter
parents:
diff changeset
  1482
	}	
peter
parents:
diff changeset
  1483
	while(val1 != val2);
peter
parents:
diff changeset
  1484
	return(val1);
peter
parents:
diff changeset
  1485
}
peter
parents:
diff changeset
  1486
/* *****************************************************************************
peter
parents:
diff changeset
  1487
                SOFTWARE API FOR PITC
peter
parents:
diff changeset
  1488
   ***************************************************************************** */
peter
parents:
diff changeset
  1489
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1490
//* \fn    AT91F_PITInit
peter
parents:
diff changeset
  1491
//* \brief System timer init : period in µsecond, system clock freq in MHz
peter
parents:
diff changeset
  1492
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1493
__inline void AT91F_PITInit(
peter
parents:
diff changeset
  1494
        AT91PS_PITC pPITC,
peter
parents:
diff changeset
  1495
        unsigned int period,
peter
parents:
diff changeset
  1496
        unsigned int pit_frequency)
peter
parents:
diff changeset
  1497
{
peter
parents:
diff changeset
  1498
	pPITC->PITC_PIMR = period? (period * pit_frequency + 8) >> 4 : 0; // +8 to avoid %10 and /10
peter
parents:
diff changeset
  1499
	pPITC->PITC_PIMR |= AT91C_PITC_PITEN;	
peter
parents:
diff changeset
  1500
}
peter
parents:
diff changeset
  1501
peter
parents:
diff changeset
  1502
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1503
//* \fn    AT91F_PITSetPIV
peter
parents:
diff changeset
  1504
//* \brief Set the PIT Periodic Interval Value
peter
parents:
diff changeset
  1505
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1506
__inline void AT91F_PITSetPIV(
peter
parents:
diff changeset
  1507
        AT91PS_PITC pPITC,
peter
parents:
diff changeset
  1508
        unsigned int piv)
peter
parents:
diff changeset
  1509
{
peter
parents:
diff changeset
  1510
	pPITC->PITC_PIMR = piv | (pPITC->PITC_PIMR & (AT91C_PITC_PITEN | AT91C_PITC_PITIEN));
peter
parents:
diff changeset
  1511
}
peter
parents:
diff changeset
  1512
peter
parents:
diff changeset
  1513
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1514
//* \fn    AT91F_PITEnableInt
peter
parents:
diff changeset
  1515
//* \brief Enable PIT periodic interrupt
peter
parents:
diff changeset
  1516
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1517
__inline void AT91F_PITEnableInt(
peter
parents:
diff changeset
  1518
        AT91PS_PITC pPITC)
peter
parents:
diff changeset
  1519
{
peter
parents:
diff changeset
  1520
	pPITC->PITC_PIMR |= AT91C_PITC_PITIEN;	
peter
parents:
diff changeset
  1521
}
peter
parents:
diff changeset
  1522
peter
parents:
diff changeset
  1523
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1524
//* \fn    AT91F_PITDisableInt
peter
parents:
diff changeset
  1525
//* \brief Disable PIT periodic interrupt
peter
parents:
diff changeset
  1526
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1527
__inline void AT91F_PITDisableInt(
peter
parents:
diff changeset
  1528
        AT91PS_PITC pPITC)
peter
parents:
diff changeset
  1529
{
peter
parents:
diff changeset
  1530
	pPITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;	
peter
parents:
diff changeset
  1531
}
peter
parents:
diff changeset
  1532
peter
parents:
diff changeset
  1533
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1534
//* \fn    AT91F_PITGetMode
peter
parents:
diff changeset
  1535
//* \brief Read PIT mode register
peter
parents:
diff changeset
  1536
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1537
__inline unsigned int AT91F_PITGetMode(
peter
parents:
diff changeset
  1538
        AT91PS_PITC pPITC)
peter
parents:
diff changeset
  1539
{
peter
parents:
diff changeset
  1540
	return(pPITC->PITC_PIMR);
peter
parents:
diff changeset
  1541
}
peter
parents:
diff changeset
  1542
peter
parents:
diff changeset
  1543
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1544
//* \fn    AT91F_PITGetStatus
peter
parents:
diff changeset
  1545
//* \brief Read PIT status register
peter
parents:
diff changeset
  1546
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1547
__inline unsigned int AT91F_PITGetStatus(
peter
parents:
diff changeset
  1548
        AT91PS_PITC pPITC)
peter
parents:
diff changeset
  1549
{
peter
parents:
diff changeset
  1550
	return(pPITC->PITC_PISR);
peter
parents:
diff changeset
  1551
}
peter
parents:
diff changeset
  1552
peter
parents:
diff changeset
  1553
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1554
//* \fn    AT91F_PITGetPIIR
peter
parents:
diff changeset
  1555
//* \brief Read PIT CPIV and PICNT without ressetting the counters
peter
parents:
diff changeset
  1556
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1557
__inline unsigned int AT91F_PITGetPIIR(
peter
parents:
diff changeset
  1558
        AT91PS_PITC pPITC)
peter
parents:
diff changeset
  1559
{
peter
parents:
diff changeset
  1560
	return(pPITC->PITC_PIIR);
peter
parents:
diff changeset
  1561
}
peter
parents:
diff changeset
  1562
peter
parents:
diff changeset
  1563
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1564
//* \fn    AT91F_PITGetPIVR
peter
parents:
diff changeset
  1565
//* \brief Read System timer CPIV and PICNT without ressetting the counters
peter
parents:
diff changeset
  1566
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1567
__inline unsigned int AT91F_PITGetPIVR(
peter
parents:
diff changeset
  1568
        AT91PS_PITC pPITC)
peter
parents:
diff changeset
  1569
{
peter
parents:
diff changeset
  1570
	return(pPITC->PITC_PIVR);
peter
parents:
diff changeset
  1571
}
peter
parents:
diff changeset
  1572
/* *****************************************************************************
peter
parents:
diff changeset
  1573
                SOFTWARE API FOR WDTC
peter
parents:
diff changeset
  1574
   ***************************************************************************** */
peter
parents:
diff changeset
  1575
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1576
//* \fn    AT91F_WDTSetMode
peter
parents:
diff changeset
  1577
//* \brief Set Watchdog Mode Register
peter
parents:
diff changeset
  1578
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1579
__inline void AT91F_WDTSetMode(
peter
parents:
diff changeset
  1580
        AT91PS_WDTC pWDTC,
peter
parents:
diff changeset
  1581
        unsigned int Mode)
peter
parents:
diff changeset
  1582
{
peter
parents:
diff changeset
  1583
	pWDTC->WDTC_WDMR = Mode;
peter
parents:
diff changeset
  1584
}
peter
parents:
diff changeset
  1585
peter
parents:
diff changeset
  1586
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1587
//* \fn    AT91F_WDTRestart
peter
parents:
diff changeset
  1588
//* \brief Restart Watchdog
peter
parents:
diff changeset
  1589
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1590
__inline void AT91F_WDTRestart(
peter
parents:
diff changeset
  1591
        AT91PS_WDTC pWDTC)
peter
parents:
diff changeset
  1592
{
peter
parents:
diff changeset
  1593
	pWDTC->WDTC_WDCR = 0xA5000001;
peter
parents:
diff changeset
  1594
}
peter
parents:
diff changeset
  1595
peter
parents:
diff changeset
  1596
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1597
//* \fn    AT91F_WDTSGettatus
peter
parents:
diff changeset
  1598
//* \brief Get Watchdog Status
peter
parents:
diff changeset
  1599
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1600
__inline unsigned int AT91F_WDTSGettatus(
peter
parents:
diff changeset
  1601
        AT91PS_WDTC pWDTC)
peter
parents:
diff changeset
  1602
{
peter
parents:
diff changeset
  1603
	return(pWDTC->WDTC_WDSR & 0x3);
peter
parents:
diff changeset
  1604
}
peter
parents:
diff changeset
  1605
peter
parents:
diff changeset
  1606
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1607
//* \fn    AT91F_WDTGetPeriod
peter
parents:
diff changeset
  1608
//* \brief Translate ms into Watchdog Compatible value
peter
parents:
diff changeset
  1609
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1610
__inline unsigned int AT91F_WDTGetPeriod(unsigned int ms)
peter
parents:
diff changeset
  1611
{
peter
parents:
diff changeset
  1612
	if ((ms < 4) || (ms > 16000))
peter
parents:
diff changeset
  1613
		return 0;
peter
parents:
diff changeset
  1614
	return((ms << 8) / 1000);
peter
parents:
diff changeset
  1615
}
peter
parents:
diff changeset
  1616
/* *****************************************************************************
peter
parents:
diff changeset
  1617
                SOFTWARE API FOR VREG
peter
parents:
diff changeset
  1618
   ***************************************************************************** */
peter
parents:
diff changeset
  1619
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1620
//* \fn    AT91F_VREG_Enable_LowPowerMode
peter
parents:
diff changeset
  1621
//* \brief Enable VREG Low Power Mode
peter
parents:
diff changeset
  1622
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1623
__inline void AT91F_VREG_Enable_LowPowerMode(
peter
parents:
diff changeset
  1624
        AT91PS_VREG pVREG)
peter
parents:
diff changeset
  1625
{
peter
parents:
diff changeset
  1626
	pVREG->VREG_MR |= AT91C_VREG_PSTDBY;	
peter
parents:
diff changeset
  1627
}
peter
parents:
diff changeset
  1628
peter
parents:
diff changeset
  1629
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1630
//* \fn    AT91F_VREG_Disable_LowPowerMode
peter
parents:
diff changeset
  1631
//* \brief Disable VREG Low Power Mode
peter
parents:
diff changeset
  1632
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1633
__inline void AT91F_VREG_Disable_LowPowerMode(
peter
parents:
diff changeset
  1634
        AT91PS_VREG pVREG)
peter
parents:
diff changeset
  1635
{
peter
parents:
diff changeset
  1636
	pVREG->VREG_MR &= ~AT91C_VREG_PSTDBY;	
peter
parents:
diff changeset
  1637
}/* *****************************************************************************
peter
parents:
diff changeset
  1638
                SOFTWARE API FOR MC
peter
parents:
diff changeset
  1639
   ***************************************************************************** */
peter
parents:
diff changeset
  1640
peter
parents:
diff changeset
  1641
#define AT91C_MC_CORRECT_KEY  ((unsigned int) 0x5A << 24) // (MC) Correct Protect Key
peter
parents:
diff changeset
  1642
peter
parents:
diff changeset
  1643
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1644
//* \fn    AT91F_MC_Remap
peter
parents:
diff changeset
  1645
//* \brief Make Remap
peter
parents:
diff changeset
  1646
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1647
__inline void AT91F_MC_Remap (void)     //
peter
parents:
diff changeset
  1648
{
peter
parents:
diff changeset
  1649
    AT91PS_MC pMC = (AT91PS_MC) AT91C_BASE_MC;
peter
parents:
diff changeset
  1650
peter
parents:
diff changeset
  1651
    pMC->MC_RCR = AT91C_MC_RCB;
peter
parents:
diff changeset
  1652
}
peter
parents:
diff changeset
  1653
peter
parents:
diff changeset
  1654
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1655
//* \fn    AT91F_MC_EFC_CfgModeReg
peter
parents:
diff changeset
  1656
//* \brief Configure the EFC Mode Register of the MC controller
peter
parents:
diff changeset
  1657
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1658
__inline void AT91F_MC_EFC_CfgModeReg (
peter
parents:
diff changeset
  1659
	AT91PS_MC pMC, // pointer to a MC controller
peter
parents:
diff changeset
  1660
	unsigned int mode)        // mode register
peter
parents:
diff changeset
  1661
{
peter
parents:
diff changeset
  1662
	// Write to the FMR register
peter
parents:
diff changeset
  1663
	pMC->MC_FMR = mode;
peter
parents:
diff changeset
  1664
}
peter
parents:
diff changeset
  1665
peter
parents:
diff changeset
  1666
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1667
//* \fn    AT91F_MC_EFC_GetModeReg
peter
parents:
diff changeset
  1668
//* \brief Return MC EFC Mode Regsiter
peter
parents:
diff changeset
  1669
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1670
__inline unsigned int AT91F_MC_EFC_GetModeReg(
peter
parents:
diff changeset
  1671
	AT91PS_MC pMC) // pointer to a MC controller
peter
parents:
diff changeset
  1672
{
peter
parents:
diff changeset
  1673
	return pMC->MC_FMR;
peter
parents:
diff changeset
  1674
}
peter
parents:
diff changeset
  1675
peter
parents:
diff changeset
  1676
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1677
//* \fn    AT91F_MC_EFC_ComputeFMCN
peter
parents:
diff changeset
  1678
//* \brief Return MC EFC Mode Regsiter
peter
parents:
diff changeset
  1679
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1680
__inline unsigned int AT91F_MC_EFC_ComputeFMCN(
peter
parents:
diff changeset
  1681
	int master_clock) // master clock in Hz
peter
parents:
diff changeset
  1682
{
peter
parents:
diff changeset
  1683
	return (master_clock/1000000 +2);
peter
parents:
diff changeset
  1684
}
peter
parents:
diff changeset
  1685
peter
parents:
diff changeset
  1686
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1687
//* \fn    AT91F_MC_EFC_PerformCmd
peter
parents:
diff changeset
  1688
//* \brief Perform EFC Command
peter
parents:
diff changeset
  1689
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1690
__inline void AT91F_MC_EFC_PerformCmd (
peter
parents:
diff changeset
  1691
	AT91PS_MC pMC, // pointer to a MC controller
peter
parents:
diff changeset
  1692
    unsigned int transfer_cmd)
peter
parents:
diff changeset
  1693
{
peter
parents:
diff changeset
  1694
	pMC->MC_FCR = transfer_cmd;	
peter
parents:
diff changeset
  1695
}
peter
parents:
diff changeset
  1696
peter
parents:
diff changeset
  1697
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1698
//* \fn    AT91F_MC_EFC_GetStatus
peter
parents:
diff changeset
  1699
//* \brief Return MC EFC Status
peter
parents:
diff changeset
  1700
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1701
__inline unsigned int AT91F_MC_EFC_GetStatus(
peter
parents:
diff changeset
  1702
	AT91PS_MC pMC) // pointer to a MC controller
peter
parents:
diff changeset
  1703
{
peter
parents:
diff changeset
  1704
	return pMC->MC_FSR;
peter
parents:
diff changeset
  1705
}
peter
parents:
diff changeset
  1706
peter
parents:
diff changeset
  1707
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1708
//* \fn    AT91F_MC_EFC_IsInterruptMasked
peter
parents:
diff changeset
  1709
//* \brief Test if EFC MC Interrupt is Masked
peter
parents:
diff changeset
  1710
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1711
__inline unsigned int AT91F_MC_EFC_IsInterruptMasked(
peter
parents:
diff changeset
  1712
        AT91PS_MC pMC,   // \arg  pointer to a MC controller
peter
parents:
diff changeset
  1713
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  1714
{
peter
parents:
diff changeset
  1715
	return (AT91F_MC_EFC_GetModeReg(pMC) & flag);
peter
parents:
diff changeset
  1716
}
peter
parents:
diff changeset
  1717
peter
parents:
diff changeset
  1718
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1719
//* \fn    AT91F_MC_EFC_IsInterruptSet
peter
parents:
diff changeset
  1720
//* \brief Test if EFC MC Interrupt is Set
peter
parents:
diff changeset
  1721
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1722
__inline unsigned int AT91F_MC_EFC_IsInterruptSet(
peter
parents:
diff changeset
  1723
        AT91PS_MC pMC,   // \arg  pointer to a MC controller
peter
parents:
diff changeset
  1724
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  1725
{
peter
parents:
diff changeset
  1726
	return (AT91F_MC_EFC_GetStatus(pMC) & flag);
peter
parents:
diff changeset
  1727
}
peter
parents:
diff changeset
  1728
peter
parents:
diff changeset
  1729
/* *****************************************************************************
peter
parents:
diff changeset
  1730
                SOFTWARE API FOR SPI
peter
parents:
diff changeset
  1731
   ***************************************************************************** */
peter
parents:
diff changeset
  1732
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1733
//* \fn    AT91F_SPI_CfgCs
peter
parents:
diff changeset
  1734
//* \brief Configure SPI chip select register
peter
parents:
diff changeset
  1735
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1736
__inline void AT91F_SPI_CfgCs (
peter
parents:
diff changeset
  1737
	AT91PS_SPI pSPI,     // pointer to a SPI controller
peter
parents:
diff changeset
  1738
	int cs,     // SPI cs number (0 to 3)
peter
parents:
diff changeset
  1739
 	int val)   //  chip select register
peter
parents:
diff changeset
  1740
{
peter
parents:
diff changeset
  1741
	//* Write to the CSR register
peter
parents:
diff changeset
  1742
	*(pSPI->SPI_CSR + cs) = val;
peter
parents:
diff changeset
  1743
}
peter
parents:
diff changeset
  1744
peter
parents:
diff changeset
  1745
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1746
//* \fn    AT91F_SPI_EnableIt
peter
parents:
diff changeset
  1747
//* \brief Enable SPI interrupt
peter
parents:
diff changeset
  1748
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1749
__inline void AT91F_SPI_EnableIt (
peter
parents:
diff changeset
  1750
	AT91PS_SPI pSPI,     // pointer to a SPI controller
peter
parents:
diff changeset
  1751
	unsigned int flag)   // IT to be enabled
peter
parents:
diff changeset
  1752
{
peter
parents:
diff changeset
  1753
	//* Write to the IER register
peter
parents:
diff changeset
  1754
	pSPI->SPI_IER = flag;
peter
parents:
diff changeset
  1755
}
peter
parents:
diff changeset
  1756
peter
parents:
diff changeset
  1757
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1758
//* \fn    AT91F_SPI_DisableIt
peter
parents:
diff changeset
  1759
//* \brief Disable SPI interrupt
peter
parents:
diff changeset
  1760
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1761
__inline void AT91F_SPI_DisableIt (
peter
parents:
diff changeset
  1762
	AT91PS_SPI pSPI, // pointer to a SPI controller
peter
parents:
diff changeset
  1763
	unsigned int flag) // IT to be disabled
peter
parents:
diff changeset
  1764
{
peter
parents:
diff changeset
  1765
	//* Write to the IDR register
peter
parents:
diff changeset
  1766
	pSPI->SPI_IDR = flag;
peter
parents:
diff changeset
  1767
}
peter
parents:
diff changeset
  1768
peter
parents:
diff changeset
  1769
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1770
//* \fn    AT91F_SPI_Reset
peter
parents:
diff changeset
  1771
//* \brief Reset the SPI controller
peter
parents:
diff changeset
  1772
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1773
__inline void AT91F_SPI_Reset (
peter
parents:
diff changeset
  1774
	AT91PS_SPI pSPI // pointer to a SPI controller
peter
parents:
diff changeset
  1775
	)
peter
parents:
diff changeset
  1776
{
peter
parents:
diff changeset
  1777
	//* Write to the CR register
peter
parents:
diff changeset
  1778
	pSPI->SPI_CR = AT91C_SPI_SWRST;
peter
parents:
diff changeset
  1779
}
peter
parents:
diff changeset
  1780
peter
parents:
diff changeset
  1781
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1782
//* \fn    AT91F_SPI_Enable
peter
parents:
diff changeset
  1783
//* \brief Enable the SPI controller
peter
parents:
diff changeset
  1784
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1785
__inline void AT91F_SPI_Enable (
peter
parents:
diff changeset
  1786
	AT91PS_SPI pSPI // pointer to a SPI controller
peter
parents:
diff changeset
  1787
	)
peter
parents:
diff changeset
  1788
{
peter
parents:
diff changeset
  1789
	//* Write to the CR register
peter
parents:
diff changeset
  1790
	pSPI->SPI_CR = AT91C_SPI_SPIEN;
peter
parents:
diff changeset
  1791
}
peter
parents:
diff changeset
  1792
peter
parents:
diff changeset
  1793
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1794
//* \fn    AT91F_SPI_Disable
peter
parents:
diff changeset
  1795
//* \brief Disable the SPI controller
peter
parents:
diff changeset
  1796
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1797
__inline void AT91F_SPI_Disable (
peter
parents:
diff changeset
  1798
	AT91PS_SPI pSPI // pointer to a SPI controller
peter
parents:
diff changeset
  1799
	)
peter
parents:
diff changeset
  1800
{
peter
parents:
diff changeset
  1801
	//* Write to the CR register
peter
parents:
diff changeset
  1802
	pSPI->SPI_CR = AT91C_SPI_SPIDIS;
peter
parents:
diff changeset
  1803
}
peter
parents:
diff changeset
  1804
peter
parents:
diff changeset
  1805
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1806
//* \fn    AT91F_SPI_CfgMode
peter
parents:
diff changeset
  1807
//* \brief Enable the SPI controller
peter
parents:
diff changeset
  1808
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1809
__inline void AT91F_SPI_CfgMode (
peter
parents:
diff changeset
  1810
	AT91PS_SPI pSPI, // pointer to a SPI controller
peter
parents:
diff changeset
  1811
	int mode)        // mode register
peter
parents:
diff changeset
  1812
{
peter
parents:
diff changeset
  1813
	//* Write to the MR register
peter
parents:
diff changeset
  1814
	pSPI->SPI_MR = mode;
peter
parents:
diff changeset
  1815
}
peter
parents:
diff changeset
  1816
peter
parents:
diff changeset
  1817
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1818
//* \fn    AT91F_SPI_CfgPCS
peter
parents:
diff changeset
  1819
//* \brief Switch to the correct PCS of SPI Mode Register : Fixed Peripheral Selected
peter
parents:
diff changeset
  1820
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1821
__inline void AT91F_SPI_CfgPCS (
peter
parents:
diff changeset
  1822
	AT91PS_SPI pSPI, // pointer to a SPI controller
peter
parents:
diff changeset
  1823
	char PCS_Device) // PCS of the Device
peter
parents:
diff changeset
  1824
{	
peter
parents:
diff changeset
  1825
 	//* Write to the MR register
peter
parents:
diff changeset
  1826
	pSPI->SPI_MR &= 0xFFF0FFFF;
peter
parents:
diff changeset
  1827
	pSPI->SPI_MR |= ( (PCS_Device<<16) & AT91C_SPI_PCS );
peter
parents:
diff changeset
  1828
}
peter
parents:
diff changeset
  1829
peter
parents:
diff changeset
  1830
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1831
//* \fn    AT91F_SPI_ReceiveFrame
peter
parents:
diff changeset
  1832
//* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
peter
parents:
diff changeset
  1833
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1834
__inline unsigned int AT91F_SPI_ReceiveFrame (
peter
parents:
diff changeset
  1835
	AT91PS_SPI pSPI,
peter
parents:
diff changeset
  1836
	char *pBuffer,
peter
parents:
diff changeset
  1837
	unsigned int szBuffer,
peter
parents:
diff changeset
  1838
	char *pNextBuffer,
peter
parents:
diff changeset
  1839
	unsigned int szNextBuffer )
peter
parents:
diff changeset
  1840
{
peter
parents:
diff changeset
  1841
	return AT91F_PDC_ReceiveFrame(
peter
parents:
diff changeset
  1842
		(AT91PS_PDC) &(pSPI->SPI_RPR),
peter
parents:
diff changeset
  1843
		pBuffer,
peter
parents:
diff changeset
  1844
		szBuffer,
peter
parents:
diff changeset
  1845
		pNextBuffer,
peter
parents:
diff changeset
  1846
		szNextBuffer);
peter
parents:
diff changeset
  1847
}
peter
parents:
diff changeset
  1848
peter
parents:
diff changeset
  1849
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1850
//* \fn    AT91F_SPI_SendFrame
peter
parents:
diff changeset
  1851
//* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is bSPIy
peter
parents:
diff changeset
  1852
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1853
__inline unsigned int AT91F_SPI_SendFrame(
peter
parents:
diff changeset
  1854
	AT91PS_SPI pSPI,
peter
parents:
diff changeset
  1855
	char *pBuffer,
peter
parents:
diff changeset
  1856
	unsigned int szBuffer,
peter
parents:
diff changeset
  1857
	char *pNextBuffer,
peter
parents:
diff changeset
  1858
	unsigned int szNextBuffer )
peter
parents:
diff changeset
  1859
{
peter
parents:
diff changeset
  1860
	return AT91F_PDC_SendFrame(
peter
parents:
diff changeset
  1861
		(AT91PS_PDC) &(pSPI->SPI_RPR),
peter
parents:
diff changeset
  1862
		pBuffer,
peter
parents:
diff changeset
  1863
		szBuffer,
peter
parents:
diff changeset
  1864
		pNextBuffer,
peter
parents:
diff changeset
  1865
		szNextBuffer);
peter
parents:
diff changeset
  1866
}
peter
parents:
diff changeset
  1867
peter
parents:
diff changeset
  1868
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1869
//* \fn    AT91F_SPI_Close
peter
parents:
diff changeset
  1870
//* \brief Close SPI: disable IT disable transfert, close PDC
peter
parents:
diff changeset
  1871
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1872
__inline void AT91F_SPI_Close (
peter
parents:
diff changeset
  1873
	AT91PS_SPI pSPI)     // \arg pointer to a SPI controller
peter
parents:
diff changeset
  1874
{
peter
parents:
diff changeset
  1875
    //* Reset all the Chip Select register
peter
parents:
diff changeset
  1876
    pSPI->SPI_CSR[0] = 0 ;
peter
parents:
diff changeset
  1877
    pSPI->SPI_CSR[1] = 0 ;
peter
parents:
diff changeset
  1878
    pSPI->SPI_CSR[2] = 0 ;
peter
parents:
diff changeset
  1879
    pSPI->SPI_CSR[3] = 0 ;
peter
parents:
diff changeset
  1880
peter
parents:
diff changeset
  1881
    //* Reset the SPI mode
peter
parents:
diff changeset
  1882
    pSPI->SPI_MR = 0  ;
peter
parents:
diff changeset
  1883
peter
parents:
diff changeset
  1884
    //* Disable all interrupts
peter
parents:
diff changeset
  1885
    pSPI->SPI_IDR = 0xFFFFFFFF ;
peter
parents:
diff changeset
  1886
peter
parents:
diff changeset
  1887
    //* Abort the Peripheral Data Transfers
peter
parents:
diff changeset
  1888
    AT91F_PDC_Close((AT91PS_PDC) &(pSPI->SPI_RPR));
peter
parents:
diff changeset
  1889
peter
parents:
diff changeset
  1890
    //* Disable receiver and transmitter and stop any activity immediately
peter
parents:
diff changeset
  1891
    pSPI->SPI_CR = AT91C_SPI_SPIDIS;
peter
parents:
diff changeset
  1892
}
peter
parents:
diff changeset
  1893
peter
parents:
diff changeset
  1894
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1895
//* \fn    AT91F_SPI_PutChar
peter
parents:
diff changeset
  1896
//* \brief Send a character,does not check if ready to send
peter
parents:
diff changeset
  1897
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1898
__inline void AT91F_SPI_PutChar (
peter
parents:
diff changeset
  1899
	AT91PS_SPI pSPI,
peter
parents:
diff changeset
  1900
	unsigned int character,
peter
parents:
diff changeset
  1901
             unsigned int cs_number )
peter
parents:
diff changeset
  1902
{
peter
parents:
diff changeset
  1903
    unsigned int value_for_cs;
peter
parents:
diff changeset
  1904
    value_for_cs = (~(1 << cs_number)) & 0xF;  //Place a zero among a 4 ONEs number
peter
parents:
diff changeset
  1905
    pSPI->SPI_TDR = (character & 0xFFFF) | (value_for_cs << 16);
peter
parents:
diff changeset
  1906
}
peter
parents:
diff changeset
  1907
peter
parents:
diff changeset
  1908
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1909
//* \fn    AT91F_SPI_GetChar
peter
parents:
diff changeset
  1910
//* \brief Receive a character,does not check if a character is available
peter
parents:
diff changeset
  1911
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1912
__inline int AT91F_SPI_GetChar (
peter
parents:
diff changeset
  1913
	const AT91PS_SPI pSPI)
peter
parents:
diff changeset
  1914
{
peter
parents:
diff changeset
  1915
    return((pSPI->SPI_RDR) & 0xFFFF);
peter
parents:
diff changeset
  1916
}
peter
parents:
diff changeset
  1917
peter
parents:
diff changeset
  1918
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1919
//* \fn    AT91F_SPI_GetInterruptMaskStatus
peter
parents:
diff changeset
  1920
//* \brief Return SPI Interrupt Mask Status
peter
parents:
diff changeset
  1921
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1922
__inline unsigned int AT91F_SPI_GetInterruptMaskStatus( // \return SPI Interrupt Mask Status
peter
parents:
diff changeset
  1923
        AT91PS_SPI pSpi) // \arg  pointer to a SPI controller
peter
parents:
diff changeset
  1924
{
peter
parents:
diff changeset
  1925
        return pSpi->SPI_IMR;
peter
parents:
diff changeset
  1926
}
peter
parents:
diff changeset
  1927
peter
parents:
diff changeset
  1928
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1929
//* \fn    AT91F_SPI_IsInterruptMasked
peter
parents:
diff changeset
  1930
//* \brief Test if SPI Interrupt is Masked
peter
parents:
diff changeset
  1931
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1932
__inline int AT91F_SPI_IsInterruptMasked(
peter
parents:
diff changeset
  1933
        AT91PS_SPI pSpi,   // \arg  pointer to a SPI controller
peter
parents:
diff changeset
  1934
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  1935
{
peter
parents:
diff changeset
  1936
        return (AT91F_SPI_GetInterruptMaskStatus(pSpi) & flag);
peter
parents:
diff changeset
  1937
}
peter
parents:
diff changeset
  1938
peter
parents:
diff changeset
  1939
/* *****************************************************************************
peter
parents:
diff changeset
  1940
                SOFTWARE API FOR USART
peter
parents:
diff changeset
  1941
   ***************************************************************************** */
peter
parents:
diff changeset
  1942
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1943
//* \fn    AT91F_US_Baudrate
peter
parents:
diff changeset
  1944
//* \brief Calculate the baudrate
peter
parents:
diff changeset
  1945
//* Standard Asynchronous Mode : 8 bits , 1 stop , no parity
peter
parents:
diff changeset
  1946
#define AT91C_US_ASYNC_MODE ( AT91C_US_USMODE_NORMAL + \
peter
parents:
diff changeset
  1947
                        AT91C_US_NBSTOP_1_BIT + \
peter
parents:
diff changeset
  1948
                        AT91C_US_PAR_NONE + \
peter
parents:
diff changeset
  1949
                        AT91C_US_CHRL_8_BITS + \
peter
parents:
diff changeset
  1950
                        AT91C_US_CLKS_CLOCK )
peter
parents:
diff changeset
  1951
peter
parents:
diff changeset
  1952
//* Standard External Asynchronous Mode : 8 bits , 1 stop , no parity
peter
parents:
diff changeset
  1953
#define AT91C_US_ASYNC_SCK_MODE ( AT91C_US_USMODE_NORMAL + \
peter
parents:
diff changeset
  1954
                            AT91C_US_NBSTOP_1_BIT + \
peter
parents:
diff changeset
  1955
                            AT91C_US_PAR_NONE + \
peter
parents:
diff changeset
  1956
                            AT91C_US_CHRL_8_BITS + \
peter
parents:
diff changeset
  1957
                            AT91C_US_CLKS_EXT )
peter
parents:
diff changeset
  1958
peter
parents:
diff changeset
  1959
//* Standard Synchronous Mode : 8 bits , 1 stop , no parity
peter
parents:
diff changeset
  1960
#define AT91C_US_SYNC_MODE ( AT91C_US_SYNC + \
peter
parents:
diff changeset
  1961
                       AT91C_US_USMODE_NORMAL + \
peter
parents:
diff changeset
  1962
                       AT91C_US_NBSTOP_1_BIT + \
peter
parents:
diff changeset
  1963
                       AT91C_US_PAR_NONE + \
peter
parents:
diff changeset
  1964
                       AT91C_US_CHRL_8_BITS + \
peter
parents:
diff changeset
  1965
                       AT91C_US_CLKS_CLOCK )
peter
parents:
diff changeset
  1966
peter
parents:
diff changeset
  1967
//* SCK used Label
peter
parents:
diff changeset
  1968
#define AT91C_US_SCK_USED (AT91C_US_CKLO | AT91C_US_CLKS_EXT)
peter
parents:
diff changeset
  1969
peter
parents:
diff changeset
  1970
//* Standard ISO T=0 Mode : 8 bits , 1 stop , parity
peter
parents:
diff changeset
  1971
#define AT91C_US_ISO_READER_MODE ( AT91C_US_USMODE_ISO7816_0 + \
peter
parents:
diff changeset
  1972
					   		 AT91C_US_CLKS_CLOCK +\
peter
parents:
diff changeset
  1973
                       		 AT91C_US_NBSTOP_1_BIT + \
peter
parents:
diff changeset
  1974
                       		 AT91C_US_PAR_EVEN + \
peter
parents:
diff changeset
  1975
                       		 AT91C_US_CHRL_8_BITS + \
peter
parents:
diff changeset
  1976
                       		 AT91C_US_CKLO +\
peter
parents:
diff changeset
  1977
                       		 AT91C_US_OVER)
peter
parents:
diff changeset
  1978
peter
parents:
diff changeset
  1979
//* Standard IRDA mode
peter
parents:
diff changeset
  1980
#define AT91C_US_ASYNC_IRDA_MODE (  AT91C_US_USMODE_IRDA + \
peter
parents:
diff changeset
  1981
                            AT91C_US_NBSTOP_1_BIT + \
peter
parents:
diff changeset
  1982
                            AT91C_US_PAR_NONE + \
peter
parents:
diff changeset
  1983
                            AT91C_US_CHRL_8_BITS + \
peter
parents:
diff changeset
  1984
                            AT91C_US_CLKS_CLOCK )
peter
parents:
diff changeset
  1985
peter
parents:
diff changeset
  1986
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1987
//* \fn    AT91F_US_Baudrate
peter
parents:
diff changeset
  1988
//* \brief Caluculate baud_value according to the main clock and the baud rate
peter
parents:
diff changeset
  1989
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  1990
__inline unsigned int AT91F_US_Baudrate (
peter
parents:
diff changeset
  1991
	const unsigned int main_clock, // \arg peripheral clock
peter
parents:
diff changeset
  1992
	const unsigned int baud_rate)  // \arg UART baudrate
peter
parents:
diff changeset
  1993
{
peter
parents:
diff changeset
  1994
	unsigned int baud_value = ((main_clock*10)/(baud_rate * 16));
peter
parents:
diff changeset
  1995
	if ((baud_value % 10) >= 5)
peter
parents:
diff changeset
  1996
		baud_value = (baud_value / 10) + 1;
peter
parents:
diff changeset
  1997
	else
peter
parents:
diff changeset
  1998
		baud_value /= 10;
peter
parents:
diff changeset
  1999
	return baud_value;
peter
parents:
diff changeset
  2000
}
peter
parents:
diff changeset
  2001
peter
parents:
diff changeset
  2002
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2003
//* \fn    AT91F_US_SetBaudrate
peter
parents:
diff changeset
  2004
//* \brief Set the baudrate according to the CPU clock
peter
parents:
diff changeset
  2005
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2006
__inline void AT91F_US_SetBaudrate (
peter
parents:
diff changeset
  2007
	AT91PS_USART pUSART,    // \arg pointer to a USART controller
peter
parents:
diff changeset
  2008
	unsigned int mainClock, // \arg peripheral clock
peter
parents:
diff changeset
  2009
	unsigned int speed)     // \arg UART baudrate
peter
parents:
diff changeset
  2010
{
peter
parents:
diff changeset
  2011
	//* Define the baud rate divisor register
peter
parents:
diff changeset
  2012
	pUSART->US_BRGR = AT91F_US_Baudrate(mainClock, speed);
peter
parents:
diff changeset
  2013
}
peter
parents:
diff changeset
  2014
peter
parents:
diff changeset
  2015
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2016
//* \fn    AT91F_US_SetTimeguard
peter
parents:
diff changeset
  2017
//* \brief Set USART timeguard
peter
parents:
diff changeset
  2018
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2019
__inline void AT91F_US_SetTimeguard (
peter
parents:
diff changeset
  2020
	AT91PS_USART pUSART,    // \arg pointer to a USART controller
peter
parents:
diff changeset
  2021
	unsigned int timeguard) // \arg timeguard value
peter
parents:
diff changeset
  2022
{
peter
parents:
diff changeset
  2023
	//* Write the Timeguard Register
peter
parents:
diff changeset
  2024
	pUSART->US_TTGR = timeguard ;
peter
parents:
diff changeset
  2025
}
peter
parents:
diff changeset
  2026
peter
parents:
diff changeset
  2027
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2028
//* \fn    AT91F_US_EnableIt
peter
parents:
diff changeset
  2029
//* \brief Enable USART IT
peter
parents:
diff changeset
  2030
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2031
__inline void AT91F_US_EnableIt (
peter
parents:
diff changeset
  2032
	AT91PS_USART pUSART, // \arg pointer to a USART controller
peter
parents:
diff changeset
  2033
	unsigned int flag)   // \arg IT to be enabled
peter
parents:
diff changeset
  2034
{
peter
parents:
diff changeset
  2035
	//* Write to the IER register
peter
parents:
diff changeset
  2036
	pUSART->US_IER = flag;
peter
parents:
diff changeset
  2037
}
peter
parents:
diff changeset
  2038
peter
parents:
diff changeset
  2039
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2040
//* \fn    AT91F_US_DisableIt
peter
parents:
diff changeset
  2041
//* \brief Disable USART IT
peter
parents:
diff changeset
  2042
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2043
__inline void AT91F_US_DisableIt (
peter
parents:
diff changeset
  2044
	AT91PS_USART pUSART, // \arg pointer to a USART controller
peter
parents:
diff changeset
  2045
	unsigned int flag)   // \arg IT to be disabled
peter
parents:
diff changeset
  2046
{
peter
parents:
diff changeset
  2047
	//* Write to the IER register
peter
parents:
diff changeset
  2048
	pUSART->US_IDR = flag;
peter
parents:
diff changeset
  2049
}
peter
parents:
diff changeset
  2050
peter
parents:
diff changeset
  2051
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2052
//* \fn    AT91F_US_Configure
peter
parents:
diff changeset
  2053
//* \brief Configure USART
peter
parents:
diff changeset
  2054
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2055
__inline void AT91F_US_Configure (
peter
parents:
diff changeset
  2056
	AT91PS_USART pUSART,     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2057
	unsigned int mainClock,  // \arg peripheral clock
peter
parents:
diff changeset
  2058
	unsigned int mode ,      // \arg mode Register to be programmed
peter
parents:
diff changeset
  2059
	unsigned int baudRate ,  // \arg baudrate to be programmed
peter
parents:
diff changeset
  2060
	unsigned int timeguard ) // \arg timeguard to be programmed
peter
parents:
diff changeset
  2061
{
peter
parents:
diff changeset
  2062
    //* Disable interrupts
peter
parents:
diff changeset
  2063
    pUSART->US_IDR = (unsigned int) -1;
peter
parents:
diff changeset
  2064
peter
parents:
diff changeset
  2065
    //* Reset receiver and transmitter
peter
parents:
diff changeset
  2066
    pUSART->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS ;
peter
parents:
diff changeset
  2067
peter
parents:
diff changeset
  2068
	//* Define the baud rate divisor register
peter
parents:
diff changeset
  2069
	AT91F_US_SetBaudrate(pUSART, mainClock, baudRate);
peter
parents:
diff changeset
  2070
peter
parents:
diff changeset
  2071
	//* Write the Timeguard Register
peter
parents:
diff changeset
  2072
	AT91F_US_SetTimeguard(pUSART, timeguard);
peter
parents:
diff changeset
  2073
peter
parents:
diff changeset
  2074
    //* Clear Transmit and Receive Counters
peter
parents:
diff changeset
  2075
    AT91F_PDC_Open((AT91PS_PDC) &(pUSART->US_RPR));
peter
parents:
diff changeset
  2076
peter
parents:
diff changeset
  2077
    //* Define the USART mode
peter
parents:
diff changeset
  2078
    pUSART->US_MR = mode  ;
peter
parents:
diff changeset
  2079
peter
parents:
diff changeset
  2080
}
peter
parents:
diff changeset
  2081
peter
parents:
diff changeset
  2082
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2083
//* \fn    AT91F_US_EnableRx
peter
parents:
diff changeset
  2084
//* \brief Enable receiving characters
peter
parents:
diff changeset
  2085
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2086
__inline void AT91F_US_EnableRx (
peter
parents:
diff changeset
  2087
	AT91PS_USART pUSART)     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2088
{
peter
parents:
diff changeset
  2089
    //* Enable receiver
peter
parents:
diff changeset
  2090
    pUSART->US_CR = AT91C_US_RXEN;
peter
parents:
diff changeset
  2091
}
peter
parents:
diff changeset
  2092
peter
parents:
diff changeset
  2093
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2094
//* \fn    AT91F_US_EnableTx
peter
parents:
diff changeset
  2095
//* \brief Enable sending characters
peter
parents:
diff changeset
  2096
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2097
__inline void AT91F_US_EnableTx (
peter
parents:
diff changeset
  2098
	AT91PS_USART pUSART)     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2099
{
peter
parents:
diff changeset
  2100
    //* Enable  transmitter
peter
parents:
diff changeset
  2101
    pUSART->US_CR = AT91C_US_TXEN;
peter
parents:
diff changeset
  2102
}
peter
parents:
diff changeset
  2103
peter
parents:
diff changeset
  2104
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2105
//* \fn    AT91F_US_ResetRx
peter
parents:
diff changeset
  2106
//* \brief Reset Receiver and re-enable it
peter
parents:
diff changeset
  2107
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2108
__inline void AT91F_US_ResetRx (
peter
parents:
diff changeset
  2109
	AT91PS_USART pUSART)     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2110
{
peter
parents:
diff changeset
  2111
	//* Reset receiver
peter
parents:
diff changeset
  2112
	pUSART->US_CR = AT91C_US_RSTRX;
peter
parents:
diff changeset
  2113
    //* Re-Enable receiver
peter
parents:
diff changeset
  2114
    pUSART->US_CR = AT91C_US_RXEN;
peter
parents:
diff changeset
  2115
}
peter
parents:
diff changeset
  2116
peter
parents:
diff changeset
  2117
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2118
//* \fn    AT91F_US_ResetTx
peter
parents:
diff changeset
  2119
//* \brief Reset Transmitter and re-enable it
peter
parents:
diff changeset
  2120
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2121
__inline void AT91F_US_ResetTx (
peter
parents:
diff changeset
  2122
	AT91PS_USART pUSART)     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2123
{
peter
parents:
diff changeset
  2124
	//* Reset transmitter
peter
parents:
diff changeset
  2125
	pUSART->US_CR = AT91C_US_RSTTX;
peter
parents:
diff changeset
  2126
    //* Enable transmitter
peter
parents:
diff changeset
  2127
    pUSART->US_CR = AT91C_US_TXEN;
peter
parents:
diff changeset
  2128
}
peter
parents:
diff changeset
  2129
peter
parents:
diff changeset
  2130
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2131
//* \fn    AT91F_US_DisableRx
peter
parents:
diff changeset
  2132
//* \brief Disable Receiver
peter
parents:
diff changeset
  2133
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2134
__inline void AT91F_US_DisableRx (
peter
parents:
diff changeset
  2135
	AT91PS_USART pUSART)     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2136
{
peter
parents:
diff changeset
  2137
    //* Disable receiver
peter
parents:
diff changeset
  2138
    pUSART->US_CR = AT91C_US_RXDIS;
peter
parents:
diff changeset
  2139
}
peter
parents:
diff changeset
  2140
peter
parents:
diff changeset
  2141
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2142
//* \fn    AT91F_US_DisableTx
peter
parents:
diff changeset
  2143
//* \brief Disable Transmitter
peter
parents:
diff changeset
  2144
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2145
__inline void AT91F_US_DisableTx (
peter
parents:
diff changeset
  2146
	AT91PS_USART pUSART)     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2147
{
peter
parents:
diff changeset
  2148
    //* Disable transmitter
peter
parents:
diff changeset
  2149
    pUSART->US_CR = AT91C_US_TXDIS;
peter
parents:
diff changeset
  2150
}
peter
parents:
diff changeset
  2151
peter
parents:
diff changeset
  2152
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2153
//* \fn    AT91F_US_Close
peter
parents:
diff changeset
  2154
//* \brief Close USART: disable IT disable receiver and transmitter, close PDC
peter
parents:
diff changeset
  2155
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2156
__inline void AT91F_US_Close (
peter
parents:
diff changeset
  2157
	AT91PS_USART pUSART)     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2158
{
peter
parents:
diff changeset
  2159
    //* Reset the baud rate divisor register
peter
parents:
diff changeset
  2160
    pUSART->US_BRGR = 0 ;
peter
parents:
diff changeset
  2161
peter
parents:
diff changeset
  2162
    //* Reset the USART mode
peter
parents:
diff changeset
  2163
    pUSART->US_MR = 0  ;
peter
parents:
diff changeset
  2164
peter
parents:
diff changeset
  2165
    //* Reset the Timeguard Register
peter
parents:
diff changeset
  2166
    pUSART->US_TTGR = 0;
peter
parents:
diff changeset
  2167
peter
parents:
diff changeset
  2168
    //* Disable all interrupts
peter
parents:
diff changeset
  2169
    pUSART->US_IDR = 0xFFFFFFFF ;
peter
parents:
diff changeset
  2170
peter
parents:
diff changeset
  2171
    //* Abort the Peripheral Data Transfers
peter
parents:
diff changeset
  2172
    AT91F_PDC_Close((AT91PS_PDC) &(pUSART->US_RPR));
peter
parents:
diff changeset
  2173
peter
parents:
diff changeset
  2174
    //* Disable receiver and transmitter and stop any activity immediately
peter
parents:
diff changeset
  2175
    pUSART->US_CR = AT91C_US_TXDIS | AT91C_US_RXDIS | AT91C_US_RSTTX | AT91C_US_RSTRX ;
peter
parents:
diff changeset
  2176
}
peter
parents:
diff changeset
  2177
peter
parents:
diff changeset
  2178
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2179
//* \fn    AT91F_US_TxReady
peter
parents:
diff changeset
  2180
//* \brief Return 1 if a character can be written in US_THR
peter
parents:
diff changeset
  2181
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2182
__inline unsigned int AT91F_US_TxReady (
peter
parents:
diff changeset
  2183
	AT91PS_USART pUSART )     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2184
{
peter
parents:
diff changeset
  2185
    return (pUSART->US_CSR & AT91C_US_TXRDY);
peter
parents:
diff changeset
  2186
}
peter
parents:
diff changeset
  2187
peter
parents:
diff changeset
  2188
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2189
//* \fn    AT91F_US_RxReady
peter
parents:
diff changeset
  2190
//* \brief Return 1 if a character can be read in US_RHR
peter
parents:
diff changeset
  2191
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2192
__inline unsigned int AT91F_US_RxReady (
peter
parents:
diff changeset
  2193
	AT91PS_USART pUSART )     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2194
{
peter
parents:
diff changeset
  2195
    return (pUSART->US_CSR & AT91C_US_RXRDY);
peter
parents:
diff changeset
  2196
}
peter
parents:
diff changeset
  2197
peter
parents:
diff changeset
  2198
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2199
//* \fn    AT91F_US_Error
peter
parents:
diff changeset
  2200
//* \brief Return the error flag
peter
parents:
diff changeset
  2201
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2202
__inline unsigned int AT91F_US_Error (
peter
parents:
diff changeset
  2203
	AT91PS_USART pUSART )     // \arg pointer to a USART controller
peter
parents:
diff changeset
  2204
{
peter
parents:
diff changeset
  2205
    return (pUSART->US_CSR &
peter
parents:
diff changeset
  2206
    	(AT91C_US_OVRE |  // Overrun error
peter
parents:
diff changeset
  2207
    	 AT91C_US_FRAME | // Framing error
peter
parents:
diff changeset
  2208
    	 AT91C_US_PARE));  // Parity error
peter
parents:
diff changeset
  2209
}
peter
parents:
diff changeset
  2210
peter
parents:
diff changeset
  2211
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2212
//* \fn    AT91F_US_PutChar
peter
parents:
diff changeset
  2213
//* \brief Send a character,does not check if ready to send
peter
parents:
diff changeset
  2214
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2215
__inline void AT91F_US_PutChar (
peter
parents:
diff changeset
  2216
	AT91PS_USART pUSART,
peter
parents:
diff changeset
  2217
	int character )
peter
parents:
diff changeset
  2218
{
peter
parents:
diff changeset
  2219
    pUSART->US_THR = (character & 0x1FF);
peter
parents:
diff changeset
  2220
}
peter
parents:
diff changeset
  2221
peter
parents:
diff changeset
  2222
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2223
//* \fn    AT91F_US_GetChar
peter
parents:
diff changeset
  2224
//* \brief Receive a character,does not check if a character is available
peter
parents:
diff changeset
  2225
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2226
__inline int AT91F_US_GetChar (
peter
parents:
diff changeset
  2227
	const AT91PS_USART pUSART)
peter
parents:
diff changeset
  2228
{
peter
parents:
diff changeset
  2229
    return((pUSART->US_RHR) & 0x1FF);
peter
parents:
diff changeset
  2230
}
peter
parents:
diff changeset
  2231
peter
parents:
diff changeset
  2232
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2233
//* \fn    AT91F_US_SendFrame
peter
parents:
diff changeset
  2234
//* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
peter
parents:
diff changeset
  2235
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2236
__inline unsigned int AT91F_US_SendFrame(
peter
parents:
diff changeset
  2237
	AT91PS_USART pUSART,
peter
parents:
diff changeset
  2238
	char *pBuffer,
peter
parents:
diff changeset
  2239
	unsigned int szBuffer,
peter
parents:
diff changeset
  2240
	char *pNextBuffer,
peter
parents:
diff changeset
  2241
	unsigned int szNextBuffer )
peter
parents:
diff changeset
  2242
{
peter
parents:
diff changeset
  2243
	return AT91F_PDC_SendFrame(
peter
parents:
diff changeset
  2244
		(AT91PS_PDC) &(pUSART->US_RPR),
peter
parents:
diff changeset
  2245
		pBuffer,
peter
parents:
diff changeset
  2246
		szBuffer,
peter
parents:
diff changeset
  2247
		pNextBuffer,
peter
parents:
diff changeset
  2248
		szNextBuffer);
peter
parents:
diff changeset
  2249
}
peter
parents:
diff changeset
  2250
peter
parents:
diff changeset
  2251
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2252
//* \fn    AT91F_US_ReceiveFrame
peter
parents:
diff changeset
  2253
//* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
peter
parents:
diff changeset
  2254
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2255
__inline unsigned int AT91F_US_ReceiveFrame (
peter
parents:
diff changeset
  2256
	AT91PS_USART pUSART,
peter
parents:
diff changeset
  2257
	char *pBuffer,
peter
parents:
diff changeset
  2258
	unsigned int szBuffer,
peter
parents:
diff changeset
  2259
	char *pNextBuffer,
peter
parents:
diff changeset
  2260
	unsigned int szNextBuffer )
peter
parents:
diff changeset
  2261
{
peter
parents:
diff changeset
  2262
	return AT91F_PDC_ReceiveFrame(
peter
parents:
diff changeset
  2263
		(AT91PS_PDC) &(pUSART->US_RPR),
peter
parents:
diff changeset
  2264
		pBuffer,
peter
parents:
diff changeset
  2265
		szBuffer,
peter
parents:
diff changeset
  2266
		pNextBuffer,
peter
parents:
diff changeset
  2267
		szNextBuffer);
peter
parents:
diff changeset
  2268
}
peter
parents:
diff changeset
  2269
peter
parents:
diff changeset
  2270
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2271
//* \fn    AT91F_US_SetIrdaFilter
peter
parents:
diff changeset
  2272
//* \brief Set the value of IrDa filter tregister
peter
parents:
diff changeset
  2273
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2274
__inline void AT91F_US_SetIrdaFilter (
peter
parents:
diff changeset
  2275
	AT91PS_USART pUSART,
peter
parents:
diff changeset
  2276
	unsigned char value
peter
parents:
diff changeset
  2277
)
peter
parents:
diff changeset
  2278
{
peter
parents:
diff changeset
  2279
	pUSART->US_IF = value;
peter
parents:
diff changeset
  2280
}
peter
parents:
diff changeset
  2281
peter
parents:
diff changeset
  2282
/* *****************************************************************************
peter
parents:
diff changeset
  2283
                SOFTWARE API FOR SSC
peter
parents:
diff changeset
  2284
   ***************************************************************************** */
peter
parents:
diff changeset
  2285
//* Define the standard I2S mode configuration
peter
parents:
diff changeset
  2286
peter
parents:
diff changeset
  2287
//* Configuration to set in the SSC Transmit Clock Mode Register
peter
parents:
diff changeset
  2288
//* Parameters :  nb_bit_by_slot : 8, 16 or 32 bits
peter
parents:
diff changeset
  2289
//* 			  nb_slot_by_frame : number of channels
peter
parents:
diff changeset
  2290
#define AT91C_I2S_ASY_MASTER_TX_SETTING(nb_bit_by_slot, nb_slot_by_frame)( +\
peter
parents:
diff changeset
  2291
									   AT91C_SSC_CKS_DIV   +\
peter
parents:
diff changeset
  2292
                            		   AT91C_SSC_CKO_CONTINOUS      +\
peter
parents:
diff changeset
  2293
                            		   AT91C_SSC_CKG_NONE    +\
peter
parents:
diff changeset
  2294
                                       AT91C_SSC_START_FALL_RF +\
peter
parents:
diff changeset
  2295
                           			   AT91C_SSC_STTOUT  +\
peter
parents:
diff changeset
  2296
                            		   ((1<<16) & AT91C_SSC_STTDLY) +\
peter
parents:
diff changeset
  2297
                            		   ((((nb_bit_by_slot*nb_slot_by_frame)/2)-1) <<24))
peter
parents:
diff changeset
  2298
peter
parents:
diff changeset
  2299
peter
parents:
diff changeset
  2300
//* Configuration to set in the SSC Transmit Frame Mode Register
peter
parents:
diff changeset
  2301
//* Parameters : nb_bit_by_slot : 8, 16 or 32 bits
peter
parents:
diff changeset
  2302
//* 			 nb_slot_by_frame : number of channels
peter
parents:
diff changeset
  2303
#define AT91C_I2S_ASY_TX_FRAME_SETTING(nb_bit_by_slot, nb_slot_by_frame)( +\
peter
parents:
diff changeset
  2304
									(nb_bit_by_slot-1)  +\
peter
parents:
diff changeset
  2305
                            		AT91C_SSC_MSBF   +\
peter
parents:
diff changeset
  2306
                            		(((nb_slot_by_frame-1)<<8) & AT91C_SSC_DATNB)  +\
peter
parents:
diff changeset
  2307
                            		(((nb_bit_by_slot-1)<<16) & AT91C_SSC_FSLEN) +\
peter
parents:
diff changeset
  2308
                            		AT91C_SSC_FSOS_NEGATIVE)
peter
parents:
diff changeset
  2309
peter
parents:
diff changeset
  2310
peter
parents:
diff changeset
  2311
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2312
//* \fn    AT91F_SSC_SetBaudrate
peter
parents:
diff changeset
  2313
//* \brief Set the baudrate according to the CPU clock
peter
parents:
diff changeset
  2314
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2315
__inline void AT91F_SSC_SetBaudrate (
peter
parents:
diff changeset
  2316
        AT91PS_SSC pSSC,        // \arg pointer to a SSC controller
peter
parents:
diff changeset
  2317
        unsigned int mainClock, // \arg peripheral clock
peter
parents:
diff changeset
  2318
        unsigned int speed)     // \arg SSC baudrate
peter
parents:
diff changeset
  2319
{
peter
parents:
diff changeset
  2320
        unsigned int baud_value;
peter
parents:
diff changeset
  2321
        //* Define the baud rate divisor register
peter
parents:
diff changeset
  2322
        if (speed == 0)
peter
parents:
diff changeset
  2323
           baud_value = 0;
peter
parents:
diff changeset
  2324
        else
peter
parents:
diff changeset
  2325
        {
peter
parents:
diff changeset
  2326
           baud_value = (unsigned int) (mainClock * 10)/(2*speed);
peter
parents:
diff changeset
  2327
           if ((baud_value % 10) >= 5)
peter
parents:
diff changeset
  2328
                  baud_value = (baud_value / 10) + 1;
peter
parents:
diff changeset
  2329
           else
peter
parents:
diff changeset
  2330
                  baud_value /= 10;
peter
parents:
diff changeset
  2331
        }
peter
parents:
diff changeset
  2332
peter
parents:
diff changeset
  2333
        pSSC->SSC_CMR = baud_value;
peter
parents:
diff changeset
  2334
}
peter
parents:
diff changeset
  2335
peter
parents:
diff changeset
  2336
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2337
//* \fn    AT91F_SSC_Configure
peter
parents:
diff changeset
  2338
//* \brief Configure SSC
peter
parents:
diff changeset
  2339
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2340
__inline void AT91F_SSC_Configure (
peter
parents:
diff changeset
  2341
             AT91PS_SSC pSSC,          // \arg pointer to a SSC controller
peter
parents:
diff changeset
  2342
             unsigned int syst_clock,  // \arg System Clock Frequency
peter
parents:
diff changeset
  2343
             unsigned int baud_rate,   // \arg Expected Baud Rate Frequency
peter
parents:
diff changeset
  2344
             unsigned int clock_rx,    // \arg Receiver Clock Parameters
peter
parents:
diff changeset
  2345
             unsigned int mode_rx,     // \arg mode Register to be programmed
peter
parents:
diff changeset
  2346
             unsigned int clock_tx,    // \arg Transmitter Clock Parameters
peter
parents:
diff changeset
  2347
             unsigned int mode_tx)     // \arg mode Register to be programmed
peter
parents:
diff changeset
  2348
{
peter
parents:
diff changeset
  2349
    //* Disable interrupts
peter
parents:
diff changeset
  2350
	pSSC->SSC_IDR = (unsigned int) -1;
peter
parents:
diff changeset
  2351
peter
parents:
diff changeset
  2352
    //* Reset receiver and transmitter
peter
parents:
diff changeset
  2353
	pSSC->SSC_CR = AT91C_SSC_SWRST | AT91C_SSC_RXDIS | AT91C_SSC_TXDIS ;
peter
parents:
diff changeset
  2354
peter
parents:
diff changeset
  2355
    //* Define the Clock Mode Register
peter
parents:
diff changeset
  2356
	AT91F_SSC_SetBaudrate(pSSC, syst_clock, baud_rate);
peter
parents:
diff changeset
  2357
peter
parents:
diff changeset
  2358
     //* Write the Receive Clock Mode Register
peter
parents:
diff changeset
  2359
	pSSC->SSC_RCMR =  clock_rx;
peter
parents:
diff changeset
  2360
peter
parents:
diff changeset
  2361
     //* Write the Transmit Clock Mode Register
peter
parents:
diff changeset
  2362
	pSSC->SSC_TCMR =  clock_tx;
peter
parents:
diff changeset
  2363
peter
parents:
diff changeset
  2364
     //* Write the Receive Frame Mode Register
peter
parents:
diff changeset
  2365
	pSSC->SSC_RFMR =  mode_rx;
peter
parents:
diff changeset
  2366
peter
parents:
diff changeset
  2367
     //* Write the Transmit Frame Mode Register
peter
parents:
diff changeset
  2368
	pSSC->SSC_TFMR =  mode_tx;
peter
parents:
diff changeset
  2369
peter
parents:
diff changeset
  2370
    //* Clear Transmit and Receive Counters
peter
parents:
diff changeset
  2371
	AT91F_PDC_Open((AT91PS_PDC) &(pSSC->SSC_RPR));
peter
parents:
diff changeset
  2372
peter
parents:
diff changeset
  2373
peter
parents:
diff changeset
  2374
}
peter
parents:
diff changeset
  2375
peter
parents:
diff changeset
  2376
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2377
//* \fn    AT91F_SSC_EnableRx
peter
parents:
diff changeset
  2378
//* \brief Enable receiving datas
peter
parents:
diff changeset
  2379
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2380
__inline void AT91F_SSC_EnableRx (
peter
parents:
diff changeset
  2381
	AT91PS_SSC pSSC)     // \arg pointer to a SSC controller
peter
parents:
diff changeset
  2382
{
peter
parents:
diff changeset
  2383
    //* Enable receiver
peter
parents:
diff changeset
  2384
    pSSC->SSC_CR = AT91C_SSC_RXEN;
peter
parents:
diff changeset
  2385
}
peter
parents:
diff changeset
  2386
peter
parents:
diff changeset
  2387
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2388
//* \fn    AT91F_SSC_DisableRx
peter
parents:
diff changeset
  2389
//* \brief Disable receiving datas
peter
parents:
diff changeset
  2390
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2391
__inline void AT91F_SSC_DisableRx (
peter
parents:
diff changeset
  2392
	AT91PS_SSC pSSC)     // \arg pointer to a SSC controller
peter
parents:
diff changeset
  2393
{
peter
parents:
diff changeset
  2394
    //* Disable receiver
peter
parents:
diff changeset
  2395
    pSSC->SSC_CR = AT91C_SSC_RXDIS;
peter
parents:
diff changeset
  2396
}
peter
parents:
diff changeset
  2397
peter
parents:
diff changeset
  2398
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2399
//* \fn    AT91F_SSC_EnableTx
peter
parents:
diff changeset
  2400
//* \brief Enable sending datas
peter
parents:
diff changeset
  2401
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2402
__inline void AT91F_SSC_EnableTx (
peter
parents:
diff changeset
  2403
	AT91PS_SSC pSSC)     // \arg pointer to a SSC controller
peter
parents:
diff changeset
  2404
{
peter
parents:
diff changeset
  2405
    //* Enable  transmitter
peter
parents:
diff changeset
  2406
    pSSC->SSC_CR = AT91C_SSC_TXEN;
peter
parents:
diff changeset
  2407
}
peter
parents:
diff changeset
  2408
peter
parents:
diff changeset
  2409
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2410
//* \fn    AT91F_SSC_DisableTx
peter
parents:
diff changeset
  2411
//* \brief Disable sending datas
peter
parents:
diff changeset
  2412
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2413
__inline void AT91F_SSC_DisableTx (
peter
parents:
diff changeset
  2414
	AT91PS_SSC pSSC)     // \arg pointer to a SSC controller
peter
parents:
diff changeset
  2415
{
peter
parents:
diff changeset
  2416
    //* Disable  transmitter
peter
parents:
diff changeset
  2417
    pSSC->SSC_CR = AT91C_SSC_TXDIS;
peter
parents:
diff changeset
  2418
}
peter
parents:
diff changeset
  2419
peter
parents:
diff changeset
  2420
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2421
//* \fn    AT91F_SSC_EnableIt
peter
parents:
diff changeset
  2422
//* \brief Enable SSC IT
peter
parents:
diff changeset
  2423
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2424
__inline void AT91F_SSC_EnableIt (
peter
parents:
diff changeset
  2425
	AT91PS_SSC pSSC, // \arg pointer to a SSC controller
peter
parents:
diff changeset
  2426
	unsigned int flag)   // \arg IT to be enabled
peter
parents:
diff changeset
  2427
{
peter
parents:
diff changeset
  2428
	//* Write to the IER register
peter
parents:
diff changeset
  2429
	pSSC->SSC_IER = flag;
peter
parents:
diff changeset
  2430
}
peter
parents:
diff changeset
  2431
peter
parents:
diff changeset
  2432
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2433
//* \fn    AT91F_SSC_DisableIt
peter
parents:
diff changeset
  2434
//* \brief Disable SSC IT
peter
parents:
diff changeset
  2435
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2436
__inline void AT91F_SSC_DisableIt (
peter
parents:
diff changeset
  2437
	AT91PS_SSC pSSC, // \arg pointer to a SSC controller
peter
parents:
diff changeset
  2438
	unsigned int flag)   // \arg IT to be disabled
peter
parents:
diff changeset
  2439
{
peter
parents:
diff changeset
  2440
	//* Write to the IDR register
peter
parents:
diff changeset
  2441
	pSSC->SSC_IDR = flag;
peter
parents:
diff changeset
  2442
}
peter
parents:
diff changeset
  2443
peter
parents:
diff changeset
  2444
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2445
//* \fn    AT91F_SSC_ReceiveFrame
peter
parents:
diff changeset
  2446
//* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initialized with Next Buffer, 0 if PDC is busy
peter
parents:
diff changeset
  2447
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2448
__inline unsigned int AT91F_SSC_ReceiveFrame (
peter
parents:
diff changeset
  2449
	AT91PS_SSC pSSC,
peter
parents:
diff changeset
  2450
	char *pBuffer,
peter
parents:
diff changeset
  2451
	unsigned int szBuffer,
peter
parents:
diff changeset
  2452
	char *pNextBuffer,
peter
parents:
diff changeset
  2453
	unsigned int szNextBuffer )
peter
parents:
diff changeset
  2454
{
peter
parents:
diff changeset
  2455
	return AT91F_PDC_ReceiveFrame(
peter
parents:
diff changeset
  2456
		(AT91PS_PDC) &(pSSC->SSC_RPR),
peter
parents:
diff changeset
  2457
		pBuffer,
peter
parents:
diff changeset
  2458
		szBuffer,
peter
parents:
diff changeset
  2459
		pNextBuffer,
peter
parents:
diff changeset
  2460
		szNextBuffer);
peter
parents:
diff changeset
  2461
}
peter
parents:
diff changeset
  2462
peter
parents:
diff changeset
  2463
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2464
//* \fn    AT91F_SSC_SendFrame
peter
parents:
diff changeset
  2465
//* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initialized with Next Buffer, 0 if PDC is busy
peter
parents:
diff changeset
  2466
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2467
__inline unsigned int AT91F_SSC_SendFrame(
peter
parents:
diff changeset
  2468
	AT91PS_SSC pSSC,
peter
parents:
diff changeset
  2469
	char *pBuffer,
peter
parents:
diff changeset
  2470
	unsigned int szBuffer,
peter
parents:
diff changeset
  2471
	char *pNextBuffer,
peter
parents:
diff changeset
  2472
	unsigned int szNextBuffer )
peter
parents:
diff changeset
  2473
{
peter
parents:
diff changeset
  2474
	return AT91F_PDC_SendFrame(
peter
parents:
diff changeset
  2475
		(AT91PS_PDC) &(pSSC->SSC_RPR),
peter
parents:
diff changeset
  2476
		pBuffer,
peter
parents:
diff changeset
  2477
		szBuffer,
peter
parents:
diff changeset
  2478
		pNextBuffer,
peter
parents:
diff changeset
  2479
		szNextBuffer);
peter
parents:
diff changeset
  2480
}
peter
parents:
diff changeset
  2481
peter
parents:
diff changeset
  2482
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2483
//* \fn    AT91F_SSC_GetInterruptMaskStatus
peter
parents:
diff changeset
  2484
//* \brief Return SSC Interrupt Mask Status
peter
parents:
diff changeset
  2485
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2486
__inline unsigned int AT91F_SSC_GetInterruptMaskStatus( // \return SSC Interrupt Mask Status
peter
parents:
diff changeset
  2487
        AT91PS_SSC pSsc) // \arg  pointer to a SSC controller
peter
parents:
diff changeset
  2488
{
peter
parents:
diff changeset
  2489
        return pSsc->SSC_IMR;
peter
parents:
diff changeset
  2490
}
peter
parents:
diff changeset
  2491
peter
parents:
diff changeset
  2492
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2493
//* \fn    AT91F_SSC_IsInterruptMasked
peter
parents:
diff changeset
  2494
//* \brief Test if SSC Interrupt is Masked
peter
parents:
diff changeset
  2495
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2496
__inline int AT91F_SSC_IsInterruptMasked(
peter
parents:
diff changeset
  2497
        AT91PS_SSC pSsc,   // \arg  pointer to a SSC controller
peter
parents:
diff changeset
  2498
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  2499
{
peter
parents:
diff changeset
  2500
        return (AT91F_SSC_GetInterruptMaskStatus(pSsc) & flag);
peter
parents:
diff changeset
  2501
}
peter
parents:
diff changeset
  2502
peter
parents:
diff changeset
  2503
/* *****************************************************************************
peter
parents:
diff changeset
  2504
                SOFTWARE API FOR TWI
peter
parents:
diff changeset
  2505
   ***************************************************************************** */
peter
parents:
diff changeset
  2506
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2507
//* \fn    AT91F_TWI_EnableIt
peter
parents:
diff changeset
  2508
//* \brief Enable TWI IT
peter
parents:
diff changeset
  2509
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2510
__inline void AT91F_TWI_EnableIt (
peter
parents:
diff changeset
  2511
	AT91PS_TWI pTWI, // \arg pointer to a TWI controller
peter
parents:
diff changeset
  2512
	unsigned int flag)   // \arg IT to be enabled
peter
parents:
diff changeset
  2513
{
peter
parents:
diff changeset
  2514
	//* Write to the IER register
peter
parents:
diff changeset
  2515
	pTWI->TWI_IER = flag;
peter
parents:
diff changeset
  2516
}
peter
parents:
diff changeset
  2517
peter
parents:
diff changeset
  2518
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2519
//* \fn    AT91F_TWI_DisableIt
peter
parents:
diff changeset
  2520
//* \brief Disable TWI IT
peter
parents:
diff changeset
  2521
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2522
__inline void AT91F_TWI_DisableIt (
peter
parents:
diff changeset
  2523
	AT91PS_TWI pTWI, // \arg pointer to a TWI controller
peter
parents:
diff changeset
  2524
	unsigned int flag)   // \arg IT to be disabled
peter
parents:
diff changeset
  2525
{
peter
parents:
diff changeset
  2526
	//* Write to the IDR register
peter
parents:
diff changeset
  2527
	pTWI->TWI_IDR = flag;
peter
parents:
diff changeset
  2528
}
peter
parents:
diff changeset
  2529
peter
parents:
diff changeset
  2530
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2531
//* \fn    AT91F_TWI_Configure
peter
parents:
diff changeset
  2532
//* \brief Configure TWI in master mode
peter
parents:
diff changeset
  2533
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2534
__inline void AT91F_TWI_Configure ( AT91PS_TWI pTWI )          // \arg pointer to a TWI controller
peter
parents:
diff changeset
  2535
{
peter
parents:
diff changeset
  2536
    //* Disable interrupts
peter
parents:
diff changeset
  2537
	pTWI->TWI_IDR = (unsigned int) -1;
peter
parents:
diff changeset
  2538
peter
parents:
diff changeset
  2539
    //* Reset peripheral
peter
parents:
diff changeset
  2540
	pTWI->TWI_CR = AT91C_TWI_SWRST;
peter
parents:
diff changeset
  2541
peter
parents:
diff changeset
  2542
	//* Set Master mode
peter
parents:
diff changeset
  2543
	pTWI->TWI_CR = AT91C_TWI_MSEN;
peter
parents:
diff changeset
  2544
peter
parents:
diff changeset
  2545
}
peter
parents:
diff changeset
  2546
peter
parents:
diff changeset
  2547
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2548
//* \fn    AT91F_TWI_GetInterruptMaskStatus
peter
parents:
diff changeset
  2549
//* \brief Return TWI Interrupt Mask Status
peter
parents:
diff changeset
  2550
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2551
__inline unsigned int AT91F_TWI_GetInterruptMaskStatus( // \return TWI Interrupt Mask Status
peter
parents:
diff changeset
  2552
        AT91PS_TWI pTwi) // \arg  pointer to a TWI controller
peter
parents:
diff changeset
  2553
{
peter
parents:
diff changeset
  2554
        return pTwi->TWI_IMR;
peter
parents:
diff changeset
  2555
}
peter
parents:
diff changeset
  2556
peter
parents:
diff changeset
  2557
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2558
//* \fn    AT91F_TWI_IsInterruptMasked
peter
parents:
diff changeset
  2559
//* \brief Test if TWI Interrupt is Masked
peter
parents:
diff changeset
  2560
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2561
__inline int AT91F_TWI_IsInterruptMasked(
peter
parents:
diff changeset
  2562
        AT91PS_TWI pTwi,   // \arg  pointer to a TWI controller
peter
parents:
diff changeset
  2563
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  2564
{
peter
parents:
diff changeset
  2565
        return (AT91F_TWI_GetInterruptMaskStatus(pTwi) & flag);
peter
parents:
diff changeset
  2566
}
peter
parents:
diff changeset
  2567
peter
parents:
diff changeset
  2568
/* *****************************************************************************
peter
parents:
diff changeset
  2569
                SOFTWARE API FOR PWMC
peter
parents:
diff changeset
  2570
   ***************************************************************************** */
peter
parents:
diff changeset
  2571
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2572
//* \fn    AT91F_PWM_GetStatus
peter
parents:
diff changeset
  2573
//* \brief Return PWM Interrupt Status
peter
parents:
diff changeset
  2574
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2575
__inline unsigned int AT91F_PWMC_GetStatus( // \return PWM Interrupt Status
peter
parents:
diff changeset
  2576
	AT91PS_PWMC pPWM) // pointer to a PWM controller
peter
parents:
diff changeset
  2577
{
peter
parents:
diff changeset
  2578
	return pPWM->PWMC_SR;
peter
parents:
diff changeset
  2579
}
peter
parents:
diff changeset
  2580
peter
parents:
diff changeset
  2581
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2582
//* \fn    AT91F_PWM_InterruptEnable
peter
parents:
diff changeset
  2583
//* \brief Enable PWM Interrupt
peter
parents:
diff changeset
  2584
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2585
__inline void AT91F_PWMC_InterruptEnable(
peter
parents:
diff changeset
  2586
        AT91PS_PWMC pPwm,   // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2587
        unsigned int flag) // \arg  PWM interrupt to be enabled
peter
parents:
diff changeset
  2588
{
peter
parents:
diff changeset
  2589
        pPwm->PWMC_IER = flag;
peter
parents:
diff changeset
  2590
}
peter
parents:
diff changeset
  2591
peter
parents:
diff changeset
  2592
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2593
//* \fn    AT91F_PWM_InterruptDisable
peter
parents:
diff changeset
  2594
//* \brief Disable PWM Interrupt
peter
parents:
diff changeset
  2595
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2596
__inline void AT91F_PWMC_InterruptDisable(
peter
parents:
diff changeset
  2597
        AT91PS_PWMC pPwm,   // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2598
        unsigned int flag) // \arg  PWM interrupt to be disabled
peter
parents:
diff changeset
  2599
{
peter
parents:
diff changeset
  2600
        pPwm->PWMC_IDR = flag;
peter
parents:
diff changeset
  2601
}
peter
parents:
diff changeset
  2602
peter
parents:
diff changeset
  2603
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2604
//* \fn    AT91F_PWM_GetInterruptMaskStatus
peter
parents:
diff changeset
  2605
//* \brief Return PWM Interrupt Mask Status
peter
parents:
diff changeset
  2606
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2607
__inline unsigned int AT91F_PWMC_GetInterruptMaskStatus( // \return PWM Interrupt Mask Status
peter
parents:
diff changeset
  2608
        AT91PS_PWMC pPwm) // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2609
{
peter
parents:
diff changeset
  2610
        return pPwm->PWMC_IMR;
peter
parents:
diff changeset
  2611
}
peter
parents:
diff changeset
  2612
peter
parents:
diff changeset
  2613
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2614
//* \fn    AT91F_PWM_IsInterruptMasked
peter
parents:
diff changeset
  2615
//* \brief Test if PWM Interrupt is Masked
peter
parents:
diff changeset
  2616
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2617
__inline unsigned int AT91F_PWMC_IsInterruptMasked(
peter
parents:
diff changeset
  2618
        AT91PS_PWMC pPWM,   // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2619
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  2620
{
peter
parents:
diff changeset
  2621
	return (AT91F_PWMC_GetInterruptMaskStatus(pPWM) & flag);
peter
parents:
diff changeset
  2622
}
peter
parents:
diff changeset
  2623
peter
parents:
diff changeset
  2624
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2625
//* \fn    AT91F_PWM_IsStatusSet
peter
parents:
diff changeset
  2626
//* \brief Test if PWM Interrupt is Set
peter
parents:
diff changeset
  2627
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2628
__inline unsigned int AT91F_PWMC_IsStatusSet(
peter
parents:
diff changeset
  2629
        AT91PS_PWMC pPWM,   // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2630
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  2631
{
peter
parents:
diff changeset
  2632
	return (AT91F_PWMC_GetStatus(pPWM) & flag);
peter
parents:
diff changeset
  2633
}
peter
parents:
diff changeset
  2634
peter
parents:
diff changeset
  2635
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2636
//* \fn    AT91F_PWM_CfgChannel
peter
parents:
diff changeset
  2637
//* \brief Test if PWM Interrupt is Set
peter
parents:
diff changeset
  2638
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2639
__inline void AT91F_PWMC_CfgChannel(
peter
parents:
diff changeset
  2640
        AT91PS_PWMC pPWM,   // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2641
        unsigned int channelId, // \arg PWM channel ID
peter
parents:
diff changeset
  2642
        unsigned int mode, // \arg  PWM mode
peter
parents:
diff changeset
  2643
        unsigned int period, // \arg PWM period
peter
parents:
diff changeset
  2644
        unsigned int duty) // \arg PWM duty cycle
peter
parents:
diff changeset
  2645
{
peter
parents:
diff changeset
  2646
	pPWM->PWMC_CH[channelId].PWMC_CMR = mode;
peter
parents:
diff changeset
  2647
	pPWM->PWMC_CH[channelId].PWMC_CDTYR = duty;
peter
parents:
diff changeset
  2648
	pPWM->PWMC_CH[channelId].PWMC_CPRDR = period;
peter
parents:
diff changeset
  2649
}
peter
parents:
diff changeset
  2650
peter
parents:
diff changeset
  2651
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2652
//* \fn    AT91F_PWM_StartChannel
peter
parents:
diff changeset
  2653
//* \brief Enable channel
peter
parents:
diff changeset
  2654
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2655
__inline void AT91F_PWMC_StartChannel(
peter
parents:
diff changeset
  2656
        AT91PS_PWMC pPWM,   // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2657
        unsigned int flag) // \arg  Channels IDs to be enabled
peter
parents:
diff changeset
  2658
{
peter
parents:
diff changeset
  2659
	pPWM->PWMC_ENA = flag;
peter
parents:
diff changeset
  2660
}
peter
parents:
diff changeset
  2661
peter
parents:
diff changeset
  2662
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2663
//* \fn    AT91F_PWM_StopChannel
peter
parents:
diff changeset
  2664
//* \brief Disable channel
peter
parents:
diff changeset
  2665
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2666
__inline void AT91F_PWMC_StopChannel(
peter
parents:
diff changeset
  2667
        AT91PS_PWMC pPWM,   // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2668
        unsigned int flag) // \arg  Channels IDs to be enabled
peter
parents:
diff changeset
  2669
{
peter
parents:
diff changeset
  2670
	pPWM->PWMC_DIS = flag;
peter
parents:
diff changeset
  2671
}
peter
parents:
diff changeset
  2672
peter
parents:
diff changeset
  2673
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2674
//* \fn    AT91F_PWM_UpdateChannel
peter
parents:
diff changeset
  2675
//* \brief Update Period or Duty Cycle
peter
parents:
diff changeset
  2676
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2677
__inline void AT91F_PWMC_UpdateChannel(
peter
parents:
diff changeset
  2678
        AT91PS_PWMC pPWM,   // \arg  pointer to a PWM controller
peter
parents:
diff changeset
  2679
        unsigned int channelId, // \arg PWM channel ID
peter
parents:
diff changeset
  2680
        unsigned int update) // \arg  Channels IDs to be enabled
peter
parents:
diff changeset
  2681
{
peter
parents:
diff changeset
  2682
	pPWM->PWMC_CH[channelId].PWMC_CUPDR = update;
peter
parents:
diff changeset
  2683
}
peter
parents:
diff changeset
  2684
peter
parents:
diff changeset
  2685
/* *****************************************************************************
peter
parents:
diff changeset
  2686
                SOFTWARE API FOR UDP
peter
parents:
diff changeset
  2687
   ***************************************************************************** */
peter
parents:
diff changeset
  2688
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2689
//* \fn    AT91F_UDP_EnableIt
peter
parents:
diff changeset
  2690
//* \brief Enable UDP IT
peter
parents:
diff changeset
  2691
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2692
__inline void AT91F_UDP_EnableIt (
peter
parents:
diff changeset
  2693
	AT91PS_UDP pUDP,     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2694
	unsigned int flag)   // \arg IT to be enabled
peter
parents:
diff changeset
  2695
{
peter
parents:
diff changeset
  2696
	//* Write to the IER register
peter
parents:
diff changeset
  2697
	pUDP->UDP_IER = flag;
peter
parents:
diff changeset
  2698
}
peter
parents:
diff changeset
  2699
peter
parents:
diff changeset
  2700
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2701
//* \fn    AT91F_UDP_DisableIt
peter
parents:
diff changeset
  2702
//* \brief Disable UDP IT
peter
parents:
diff changeset
  2703
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2704
__inline void AT91F_UDP_DisableIt (
peter
parents:
diff changeset
  2705
	AT91PS_UDP pUDP,     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2706
	unsigned int flag)   // \arg IT to be disabled
peter
parents:
diff changeset
  2707
{
peter
parents:
diff changeset
  2708
	//* Write to the IDR register
peter
parents:
diff changeset
  2709
	pUDP->UDP_IDR = flag;
peter
parents:
diff changeset
  2710
}
peter
parents:
diff changeset
  2711
peter
parents:
diff changeset
  2712
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2713
//* \fn    AT91F_UDP_SetAddress
peter
parents:
diff changeset
  2714
//* \brief Set UDP functional address
peter
parents:
diff changeset
  2715
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2716
__inline void AT91F_UDP_SetAddress (
peter
parents:
diff changeset
  2717
	AT91PS_UDP pUDP,     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2718
	unsigned char address)   // \arg new UDP address
peter
parents:
diff changeset
  2719
{
peter
parents:
diff changeset
  2720
	pUDP->UDP_FADDR = (AT91C_UDP_FEN | address);
peter
parents:
diff changeset
  2721
}
peter
parents:
diff changeset
  2722
peter
parents:
diff changeset
  2723
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2724
//* \fn    AT91F_UDP_EnableEp
peter
parents:
diff changeset
  2725
//* \brief Enable Endpoint
peter
parents:
diff changeset
  2726
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2727
__inline void AT91F_UDP_EnableEp (
peter
parents:
diff changeset
  2728
	AT91PS_UDP pUDP,     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2729
	unsigned char endpoint)   // \arg endpoint number
peter
parents:
diff changeset
  2730
{
peter
parents:
diff changeset
  2731
	pUDP->UDP_CSR[endpoint] |= AT91C_UDP_EPEDS;
peter
parents:
diff changeset
  2732
}
peter
parents:
diff changeset
  2733
peter
parents:
diff changeset
  2734
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2735
//* \fn    AT91F_UDP_DisableEp
peter
parents:
diff changeset
  2736
//* \brief Enable Endpoint
peter
parents:
diff changeset
  2737
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2738
__inline void AT91F_UDP_DisableEp (
peter
parents:
diff changeset
  2739
	AT91PS_UDP pUDP,     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2740
	unsigned char endpoint)   // \arg endpoint number
peter
parents:
diff changeset
  2741
{
peter
parents:
diff changeset
  2742
	pUDP->UDP_CSR[endpoint] &= ~AT91C_UDP_EPEDS;
peter
parents:
diff changeset
  2743
}
peter
parents:
diff changeset
  2744
peter
parents:
diff changeset
  2745
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2746
//* \fn    AT91F_UDP_SetState
peter
parents:
diff changeset
  2747
//* \brief Set UDP Device state
peter
parents:
diff changeset
  2748
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2749
__inline void AT91F_UDP_SetState (
peter
parents:
diff changeset
  2750
	AT91PS_UDP pUDP,     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2751
	unsigned int flag)   // \arg new UDP address
peter
parents:
diff changeset
  2752
{
peter
parents:
diff changeset
  2753
	pUDP->UDP_GLBSTATE  &= ~(AT91C_UDP_FADDEN | AT91C_UDP_CONFG);
peter
parents:
diff changeset
  2754
	pUDP->UDP_GLBSTATE  |= flag;
peter
parents:
diff changeset
  2755
}
peter
parents:
diff changeset
  2756
peter
parents:
diff changeset
  2757
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2758
//* \fn    AT91F_UDP_GetState
peter
parents:
diff changeset
  2759
//* \brief return UDP Device state
peter
parents:
diff changeset
  2760
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2761
__inline unsigned int AT91F_UDP_GetState ( // \return the UDP device state
peter
parents:
diff changeset
  2762
	AT91PS_UDP pUDP)     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2763
{
peter
parents:
diff changeset
  2764
	return (pUDP->UDP_GLBSTATE  & (AT91C_UDP_FADDEN | AT91C_UDP_CONFG));
peter
parents:
diff changeset
  2765
}
peter
parents:
diff changeset
  2766
peter
parents:
diff changeset
  2767
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2768
//* \fn    AT91F_UDP_ResetEp
peter
parents:
diff changeset
  2769
//* \brief Reset UDP endpoint
peter
parents:
diff changeset
  2770
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2771
__inline void AT91F_UDP_ResetEp ( // \return the UDP device state
peter
parents:
diff changeset
  2772
	AT91PS_UDP pUDP,     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2773
	unsigned int flag)   // \arg Endpoints to be reset
peter
parents:
diff changeset
  2774
{
peter
parents:
diff changeset
  2775
	pUDP->UDP_RSTEP = flag;
peter
parents:
diff changeset
  2776
	pUDP->UDP_RSTEP = 0;
peter
parents:
diff changeset
  2777
}
peter
parents:
diff changeset
  2778
peter
parents:
diff changeset
  2779
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2780
//* \fn    AT91F_UDP_EpStall
peter
parents:
diff changeset
  2781
//* \brief Endpoint will STALL requests
peter
parents:
diff changeset
  2782
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2783
__inline void AT91F_UDP_EpStall(
peter
parents:
diff changeset
  2784
	AT91PS_UDP pUDP,     // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2785
	unsigned char endpoint)   // \arg endpoint number
peter
parents:
diff changeset
  2786
{
peter
parents:
diff changeset
  2787
	pUDP->UDP_CSR[endpoint] |= AT91C_UDP_FORCESTALL;
peter
parents:
diff changeset
  2788
}
peter
parents:
diff changeset
  2789
peter
parents:
diff changeset
  2790
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2791
//* \fn    AT91F_UDP_EpWrite
peter
parents:
diff changeset
  2792
//* \brief Write value in the DPR
peter
parents:
diff changeset
  2793
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2794
__inline void AT91F_UDP_EpWrite(
peter
parents:
diff changeset
  2795
	AT91PS_UDP pUDP,         // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2796
	unsigned char endpoint,  // \arg endpoint number
peter
parents:
diff changeset
  2797
	unsigned char value)     // \arg value to be written in the DPR
peter
parents:
diff changeset
  2798
{
peter
parents:
diff changeset
  2799
	pUDP->UDP_FDR[endpoint] = value;
peter
parents:
diff changeset
  2800
}
peter
parents:
diff changeset
  2801
peter
parents:
diff changeset
  2802
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2803
//* \fn    AT91F_UDP_EpRead
peter
parents:
diff changeset
  2804
//* \brief Return value from the DPR
peter
parents:
diff changeset
  2805
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2806
__inline unsigned int AT91F_UDP_EpRead(
peter
parents:
diff changeset
  2807
	AT91PS_UDP pUDP,         // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2808
	unsigned char endpoint)  // \arg endpoint number
peter
parents:
diff changeset
  2809
{
peter
parents:
diff changeset
  2810
	return pUDP->UDP_FDR[endpoint];
peter
parents:
diff changeset
  2811
}
peter
parents:
diff changeset
  2812
peter
parents:
diff changeset
  2813
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2814
//* \fn    AT91F_UDP_EpEndOfWr
peter
parents:
diff changeset
  2815
//* \brief Notify the UDP that values in DPR are ready to be sent
peter
parents:
diff changeset
  2816
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2817
__inline void AT91F_UDP_EpEndOfWr(
peter
parents:
diff changeset
  2818
	AT91PS_UDP pUDP,         // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2819
	unsigned char endpoint)  // \arg endpoint number
peter
parents:
diff changeset
  2820
{
peter
parents:
diff changeset
  2821
	pUDP->UDP_CSR[endpoint] |= AT91C_UDP_TXPKTRDY;
peter
parents:
diff changeset
  2822
}
peter
parents:
diff changeset
  2823
peter
parents:
diff changeset
  2824
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2825
//* \fn    AT91F_UDP_EpClear
peter
parents:
diff changeset
  2826
//* \brief Clear flag in the endpoint CSR register
peter
parents:
diff changeset
  2827
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2828
__inline void AT91F_UDP_EpClear(
peter
parents:
diff changeset
  2829
	AT91PS_UDP pUDP,         // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2830
	unsigned char endpoint,  // \arg endpoint number
peter
parents:
diff changeset
  2831
	unsigned int flag)       // \arg flag to be cleared
peter
parents:
diff changeset
  2832
{
peter
parents:
diff changeset
  2833
	pUDP->UDP_CSR[endpoint] &= ~(flag);
peter
parents:
diff changeset
  2834
}
peter
parents:
diff changeset
  2835
peter
parents:
diff changeset
  2836
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2837
//* \fn    AT91F_UDP_EpSet
peter
parents:
diff changeset
  2838
//* \brief Set flag in the endpoint CSR register
peter
parents:
diff changeset
  2839
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2840
__inline void AT91F_UDP_EpSet(
peter
parents:
diff changeset
  2841
	AT91PS_UDP pUDP,         // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2842
	unsigned char endpoint,  // \arg endpoint number
peter
parents:
diff changeset
  2843
	unsigned int flag)       // \arg flag to be cleared
peter
parents:
diff changeset
  2844
{
peter
parents:
diff changeset
  2845
	pUDP->UDP_CSR[endpoint] |= flag;
peter
parents:
diff changeset
  2846
}
peter
parents:
diff changeset
  2847
peter
parents:
diff changeset
  2848
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2849
//* \fn    AT91F_UDP_EpStatus
peter
parents:
diff changeset
  2850
//* \brief Return the endpoint CSR register
peter
parents:
diff changeset
  2851
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2852
__inline unsigned int AT91F_UDP_EpStatus(
peter
parents:
diff changeset
  2853
	AT91PS_UDP pUDP,         // \arg pointer to a UDP controller
peter
parents:
diff changeset
  2854
	unsigned char endpoint)  // \arg endpoint number
peter
parents:
diff changeset
  2855
{
peter
parents:
diff changeset
  2856
	return pUDP->UDP_CSR[endpoint];
peter
parents:
diff changeset
  2857
}
peter
parents:
diff changeset
  2858
peter
parents:
diff changeset
  2859
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2860
//* \fn    AT91F_UDP_GetInterruptMaskStatus
peter
parents:
diff changeset
  2861
//* \brief Return UDP Interrupt Mask Status
peter
parents:
diff changeset
  2862
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2863
__inline unsigned int AT91F_UDP_GetInterruptMaskStatus(
peter
parents:
diff changeset
  2864
  AT91PS_UDP pUdp)        // \arg  pointer to a UDP controller
peter
parents:
diff changeset
  2865
{
peter
parents:
diff changeset
  2866
  return pUdp->UDP_IMR;
peter
parents:
diff changeset
  2867
}
peter
parents:
diff changeset
  2868
peter
parents:
diff changeset
  2869
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2870
//* \fn    AT91F_UDP_IsInterruptMasked
peter
parents:
diff changeset
  2871
//* \brief Test if UDP Interrupt is Masked
peter
parents:
diff changeset
  2872
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2873
__inline int AT91F_UDP_IsInterruptMasked(
peter
parents:
diff changeset
  2874
  AT91PS_UDP pUdp,       // \arg  pointer to a UDP controller
peter
parents:
diff changeset
  2875
  unsigned int flag)     // \arg  flag to be tested
peter
parents:
diff changeset
  2876
{
peter
parents:
diff changeset
  2877
  return (AT91F_UDP_GetInterruptMaskStatus(pUdp) & flag);
peter
parents:
diff changeset
  2878
}
peter
parents:
diff changeset
  2879
peter
parents:
diff changeset
  2880
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  2881
//  \fn    AT91F_UDP_InterruptStatusRegister
peter
parents:
diff changeset
  2882
//  \brief Return the Interrupt Status Register
peter
parents:
diff changeset
  2883
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  2884
__inline unsigned int AT91F_UDP_InterruptStatusRegister(
peter
parents:
diff changeset
  2885
  AT91PS_UDP pUDP )      // \arg  pointer to a UDP controller
peter
parents:
diff changeset
  2886
{
peter
parents:
diff changeset
  2887
  return pUDP->UDP_ISR;
peter
parents:
diff changeset
  2888
}
peter
parents:
diff changeset
  2889
peter
parents:
diff changeset
  2890
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  2891
//  \fn    AT91F_UDP_InterruptClearRegister
peter
parents:
diff changeset
  2892
//  \brief Clear Interrupt Register
peter
parents:
diff changeset
  2893
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  2894
__inline void AT91F_UDP_InterruptClearRegister (
peter
parents:
diff changeset
  2895
  AT91PS_UDP pUDP,       // \arg pointer to UDP controller
peter
parents:
diff changeset
  2896
  unsigned int flag)     // \arg IT to be cleat
peter
parents:
diff changeset
  2897
{
peter
parents:
diff changeset
  2898
  pUDP->UDP_ICR = flag;
peter
parents:
diff changeset
  2899
}
peter
parents:
diff changeset
  2900
peter
parents:
diff changeset
  2901
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  2902
//  \fn    AT91F_UDP_EnableTransceiver
peter
parents:
diff changeset
  2903
//  \brief Enable transceiver
peter
parents:
diff changeset
  2904
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  2905
__inline void AT91F_UDP_EnableTransceiver(
peter
parents:
diff changeset
  2906
  AT91PS_UDP pUDP )      // \arg  pointer to a UDP controller
peter
parents:
diff changeset
  2907
{
peter
parents:
diff changeset
  2908
    pUDP->UDP_TXVC &= ~AT91C_UDP_TXVDIS;
peter
parents:
diff changeset
  2909
}
peter
parents:
diff changeset
  2910
peter
parents:
diff changeset
  2911
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  2912
//  \fn    AT91F_UDP_DisableTransceiver
peter
parents:
diff changeset
  2913
//  \brief Disable transceiver
peter
parents:
diff changeset
  2914
// ----------------------------------------------------------------------------
peter
parents:
diff changeset
  2915
__inline void AT91F_UDP_DisableTransceiver(
peter
parents:
diff changeset
  2916
  AT91PS_UDP pUDP )      // \arg  pointer to a UDP controller
peter
parents:
diff changeset
  2917
{
peter
parents:
diff changeset
  2918
    pUDP->UDP_TXVC = AT91C_UDP_TXVDIS;
peter
parents:
diff changeset
  2919
}
peter
parents:
diff changeset
  2920
peter
parents:
diff changeset
  2921
/* *****************************************************************************
peter
parents:
diff changeset
  2922
                SOFTWARE API FOR TC
peter
parents:
diff changeset
  2923
   ***************************************************************************** */
peter
parents:
diff changeset
  2924
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2925
//* \fn    AT91F_TC_InterruptEnable
peter
parents:
diff changeset
  2926
//* \brief Enable TC Interrupt
peter
parents:
diff changeset
  2927
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2928
__inline void AT91F_TC_InterruptEnable(
peter
parents:
diff changeset
  2929
        AT91PS_TC pTc,   // \arg  pointer to a TC controller
peter
parents:
diff changeset
  2930
        unsigned int flag) // \arg  TC interrupt to be enabled
peter
parents:
diff changeset
  2931
{
peter
parents:
diff changeset
  2932
        pTc->TC_IER = flag;
peter
parents:
diff changeset
  2933
}
peter
parents:
diff changeset
  2934
peter
parents:
diff changeset
  2935
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2936
//* \fn    AT91F_TC_InterruptDisable
peter
parents:
diff changeset
  2937
//* \brief Disable TC Interrupt
peter
parents:
diff changeset
  2938
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2939
__inline void AT91F_TC_InterruptDisable(
peter
parents:
diff changeset
  2940
        AT91PS_TC pTc,   // \arg  pointer to a TC controller
peter
parents:
diff changeset
  2941
        unsigned int flag) // \arg  TC interrupt to be disabled
peter
parents:
diff changeset
  2942
{
peter
parents:
diff changeset
  2943
        pTc->TC_IDR = flag;
peter
parents:
diff changeset
  2944
}
peter
parents:
diff changeset
  2945
peter
parents:
diff changeset
  2946
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2947
//* \fn    AT91F_TC_GetInterruptMaskStatus
peter
parents:
diff changeset
  2948
//* \brief Return TC Interrupt Mask Status
peter
parents:
diff changeset
  2949
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2950
__inline unsigned int AT91F_TC_GetInterruptMaskStatus( // \return TC Interrupt Mask Status
peter
parents:
diff changeset
  2951
        AT91PS_TC pTc) // \arg  pointer to a TC controller
peter
parents:
diff changeset
  2952
{
peter
parents:
diff changeset
  2953
        return pTc->TC_IMR;
peter
parents:
diff changeset
  2954
}
peter
parents:
diff changeset
  2955
peter
parents:
diff changeset
  2956
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2957
//* \fn    AT91F_TC_IsInterruptMasked
peter
parents:
diff changeset
  2958
//* \brief Test if TC Interrupt is Masked
peter
parents:
diff changeset
  2959
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2960
__inline int AT91F_TC_IsInterruptMasked(
peter
parents:
diff changeset
  2961
        AT91PS_TC pTc,   // \arg  pointer to a TC controller
peter
parents:
diff changeset
  2962
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  2963
{
peter
parents:
diff changeset
  2964
        return (AT91F_TC_GetInterruptMaskStatus(pTc) & flag);
peter
parents:
diff changeset
  2965
}
peter
parents:
diff changeset
  2966
peter
parents:
diff changeset
  2967
/* *****************************************************************************
peter
parents:
diff changeset
  2968
                SOFTWARE API FOR CAN
peter
parents:
diff changeset
  2969
   ***************************************************************************** */
peter
parents:
diff changeset
  2970
#define	STANDARD_FORMAT 0
peter
parents:
diff changeset
  2971
#define	EXTENDED_FORMAT 1
peter
parents:
diff changeset
  2972
peter
parents:
diff changeset
  2973
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2974
//* \fn    AT91F_InitMailboxRegisters()
peter
parents:
diff changeset
  2975
//* \brief Configure the corresponding mailbox
peter
parents:
diff changeset
  2976
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2977
__inline void AT91F_InitMailboxRegisters(AT91PS_CAN_MB	CAN_Mailbox,
peter
parents:
diff changeset
  2978
								int  			mode_reg,
peter
parents:
diff changeset
  2979
								int 			acceptance_mask_reg,
peter
parents:
diff changeset
  2980
								int  			id_reg,
peter
parents:
diff changeset
  2981
								int  			data_low_reg,
peter
parents:
diff changeset
  2982
								int  			data_high_reg,
peter
parents:
diff changeset
  2983
								int  			control_reg)
peter
parents:
diff changeset
  2984
{
peter
parents:
diff changeset
  2985
	CAN_Mailbox->CAN_MB_MCR 	= 0x0;
peter
parents:
diff changeset
  2986
	CAN_Mailbox->CAN_MB_MMR 	= mode_reg;
peter
parents:
diff changeset
  2987
	CAN_Mailbox->CAN_MB_MAM 	= acceptance_mask_reg;
peter
parents:
diff changeset
  2988
	CAN_Mailbox->CAN_MB_MID 	= id_reg;
peter
parents:
diff changeset
  2989
	CAN_Mailbox->CAN_MB_MDL 	= data_low_reg; 		
peter
parents:
diff changeset
  2990
	CAN_Mailbox->CAN_MB_MDH 	= data_high_reg;
peter
parents:
diff changeset
  2991
	CAN_Mailbox->CAN_MB_MCR 	= control_reg;
peter
parents:
diff changeset
  2992
}
peter
parents:
diff changeset
  2993
peter
parents:
diff changeset
  2994
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2995
//* \fn    AT91F_EnableCAN()
peter
parents:
diff changeset
  2996
//* \brief
peter
parents:
diff changeset
  2997
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  2998
__inline void AT91F_EnableCAN(
peter
parents:
diff changeset
  2999
	AT91PS_CAN pCAN)     // pointer to a CAN controller
peter
parents:
diff changeset
  3000
{
peter
parents:
diff changeset
  3001
	pCAN->CAN_MR |= AT91C_CAN_CANEN;
peter
parents:
diff changeset
  3002
peter
parents:
diff changeset
  3003
	// Wait for WAKEUP flag raising <=> 11-recessive-bit were scanned by the transceiver
peter
parents:
diff changeset
  3004
	while( (pCAN->CAN_SR & AT91C_CAN_WAKEUP) != AT91C_CAN_WAKEUP );
peter
parents:
diff changeset
  3005
}
peter
parents:
diff changeset
  3006
peter
parents:
diff changeset
  3007
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3008
//* \fn    AT91F_DisableCAN()
peter
parents:
diff changeset
  3009
//* \brief
peter
parents:
diff changeset
  3010
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3011
__inline void AT91F_DisableCAN(
peter
parents:
diff changeset
  3012
	AT91PS_CAN pCAN)     // pointer to a CAN controller
peter
parents:
diff changeset
  3013
{
peter
parents:
diff changeset
  3014
	pCAN->CAN_MR &= ~AT91C_CAN_CANEN;
peter
parents:
diff changeset
  3015
}
peter
parents:
diff changeset
  3016
peter
parents:
diff changeset
  3017
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3018
//* \fn    AT91F_CAN_EnableIt
peter
parents:
diff changeset
  3019
//* \brief Enable CAN interrupt
peter
parents:
diff changeset
  3020
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3021
__inline void AT91F_CAN_EnableIt (
peter
parents:
diff changeset
  3022
	AT91PS_CAN pCAN,     // pointer to a CAN controller
peter
parents:
diff changeset
  3023
	unsigned int flag)   // IT to be enabled
peter
parents:
diff changeset
  3024
{
peter
parents:
diff changeset
  3025
	//* Write to the IER register
peter
parents:
diff changeset
  3026
	pCAN->CAN_IER = flag;
peter
parents:
diff changeset
  3027
}
peter
parents:
diff changeset
  3028
peter
parents:
diff changeset
  3029
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3030
//* \fn    AT91F_CAN_DisableIt
peter
parents:
diff changeset
  3031
//* \brief Disable CAN interrupt
peter
parents:
diff changeset
  3032
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3033
__inline void AT91F_CAN_DisableIt (
peter
parents:
diff changeset
  3034
	AT91PS_CAN pCAN, // pointer to a CAN controller
peter
parents:
diff changeset
  3035
	unsigned int flag) // IT to be disabled
peter
parents:
diff changeset
  3036
{
peter
parents:
diff changeset
  3037
	//* Write to the IDR register
peter
parents:
diff changeset
  3038
	pCAN->CAN_IDR = flag;
peter
parents:
diff changeset
  3039
}
peter
parents:
diff changeset
  3040
peter
parents:
diff changeset
  3041
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3042
//* \fn    AT91F_CAN_GetStatus
peter
parents:
diff changeset
  3043
//* \brief Return CAN Interrupt Status
peter
parents:
diff changeset
  3044
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3045
__inline unsigned int AT91F_CAN_GetStatus( // \return CAN Interrupt Status
peter
parents:
diff changeset
  3046
	AT91PS_CAN pCAN) // pointer to a CAN controller
peter
parents:
diff changeset
  3047
{
peter
parents:
diff changeset
  3048
	return pCAN->CAN_SR;
peter
parents:
diff changeset
  3049
}
peter
parents:
diff changeset
  3050
peter
parents:
diff changeset
  3051
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3052
//* \fn    AT91F_CAN_GetInterruptMaskStatus
peter
parents:
diff changeset
  3053
//* \brief Return CAN Interrupt Mask Status
peter
parents:
diff changeset
  3054
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3055
__inline unsigned int AT91F_CAN_GetInterruptMaskStatus( // \return CAN Interrupt Mask Status
peter
parents:
diff changeset
  3056
	AT91PS_CAN pCAN) // pointer to a CAN controller
peter
parents:
diff changeset
  3057
{
peter
parents:
diff changeset
  3058
	return pCAN->CAN_IMR;
peter
parents:
diff changeset
  3059
}
peter
parents:
diff changeset
  3060
peter
parents:
diff changeset
  3061
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3062
//* \fn    AT91F_CAN_IsInterruptMasked
peter
parents:
diff changeset
  3063
//* \brief Test if CAN Interrupt is Masked
peter
parents:
diff changeset
  3064
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3065
__inline unsigned int AT91F_CAN_IsInterruptMasked(
peter
parents:
diff changeset
  3066
        AT91PS_CAN pCAN,   // \arg  pointer to a CAN controller
peter
parents:
diff changeset
  3067
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  3068
{
peter
parents:
diff changeset
  3069
	return (AT91F_CAN_GetInterruptMaskStatus(pCAN) & flag);
peter
parents:
diff changeset
  3070
}
peter
parents:
diff changeset
  3071
peter
parents:
diff changeset
  3072
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3073
//* \fn    AT91F_CAN_IsStatusSet
peter
parents:
diff changeset
  3074
//* \brief Test if CAN Interrupt is Set
peter
parents:
diff changeset
  3075
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3076
__inline unsigned int AT91F_CAN_IsStatusSet(
peter
parents:
diff changeset
  3077
        AT91PS_CAN pCAN,   // \arg  pointer to a CAN controller
peter
parents:
diff changeset
  3078
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  3079
{
peter
parents:
diff changeset
  3080
	return (AT91F_CAN_GetStatus(pCAN) & flag);
peter
parents:
diff changeset
  3081
}
peter
parents:
diff changeset
  3082
peter
parents:
diff changeset
  3083
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3084
//* \fn    AT91F_CAN_CfgModeReg
peter
parents:
diff changeset
  3085
//* \brief Configure the Mode Register of the CAN controller
peter
parents:
diff changeset
  3086
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3087
__inline void AT91F_CAN_CfgModeReg (
peter
parents:
diff changeset
  3088
	AT91PS_CAN pCAN, // pointer to a CAN controller
peter
parents:
diff changeset
  3089
	unsigned int mode)        // mode register
peter
parents:
diff changeset
  3090
{
peter
parents:
diff changeset
  3091
	//* Write to the MR register
peter
parents:
diff changeset
  3092
	pCAN->CAN_MR = mode;
peter
parents:
diff changeset
  3093
}
peter
parents:
diff changeset
  3094
peter
parents:
diff changeset
  3095
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3096
//* \fn    AT91F_CAN_GetModeReg
peter
parents:
diff changeset
  3097
//* \brief Return the Mode Register of the CAN controller value
peter
parents:
diff changeset
  3098
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3099
__inline unsigned int AT91F_CAN_GetModeReg (
peter
parents:
diff changeset
  3100
	AT91PS_CAN pCAN // pointer to a CAN controller
peter
parents:
diff changeset
  3101
	)
peter
parents:
diff changeset
  3102
{
peter
parents:
diff changeset
  3103
	return pCAN->CAN_MR;	
peter
parents:
diff changeset
  3104
}
peter
parents:
diff changeset
  3105
peter
parents:
diff changeset
  3106
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3107
//* \fn    AT91F_CAN_CfgBaudrateReg
peter
parents:
diff changeset
  3108
//* \brief Configure the Baudrate of the CAN controller for the network
peter
parents:
diff changeset
  3109
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3110
__inline void AT91F_CAN_CfgBaudrateReg (
peter
parents:
diff changeset
  3111
	AT91PS_CAN pCAN, // pointer to a CAN controller
peter
parents:
diff changeset
  3112
	unsigned int baudrate_cfg)
peter
parents:
diff changeset
  3113
{
peter
parents:
diff changeset
  3114
	//* Write to the BR register
peter
parents:
diff changeset
  3115
	pCAN->CAN_BR = baudrate_cfg;	
peter
parents:
diff changeset
  3116
}
peter
parents:
diff changeset
  3117
peter
parents:
diff changeset
  3118
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3119
//* \fn    AT91F_CAN_GetBaudrate
peter
parents:
diff changeset
  3120
//* \brief Return the Baudrate of the CAN controller for the network value
peter
parents:
diff changeset
  3121
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3122
__inline unsigned int AT91F_CAN_GetBaudrate (
peter
parents:
diff changeset
  3123
	AT91PS_CAN pCAN // pointer to a CAN controller
peter
parents:
diff changeset
  3124
	)
peter
parents:
diff changeset
  3125
{
peter
parents:
diff changeset
  3126
	return pCAN->CAN_BR;	
peter
parents:
diff changeset
  3127
}
peter
parents:
diff changeset
  3128
peter
parents:
diff changeset
  3129
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3130
//* \fn    AT91F_CAN_GetInternalCounter
peter
parents:
diff changeset
  3131
//* \brief Return CAN Timer Regsiter Value
peter
parents:
diff changeset
  3132
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3133
__inline unsigned int AT91F_CAN_GetInternalCounter (
peter
parents:
diff changeset
  3134
	AT91PS_CAN pCAN // pointer to a CAN controller
peter
parents:
diff changeset
  3135
	)
peter
parents:
diff changeset
  3136
{
peter
parents:
diff changeset
  3137
	return pCAN->CAN_TIM;	
peter
parents:
diff changeset
  3138
}
peter
parents:
diff changeset
  3139
peter
parents:
diff changeset
  3140
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3141
//* \fn    AT91F_CAN_GetTimestamp
peter
parents:
diff changeset
  3142
//* \brief Return CAN Timestamp Register Value
peter
parents:
diff changeset
  3143
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3144
__inline unsigned int AT91F_CAN_GetTimestamp (
peter
parents:
diff changeset
  3145
	AT91PS_CAN pCAN // pointer to a CAN controller
peter
parents:
diff changeset
  3146
	)
peter
parents:
diff changeset
  3147
{
peter
parents:
diff changeset
  3148
	return pCAN->CAN_TIMESTP;	
peter
parents:
diff changeset
  3149
}
peter
parents:
diff changeset
  3150
peter
parents:
diff changeset
  3151
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3152
//* \fn    AT91F_CAN_GetErrorCounter
peter
parents:
diff changeset
  3153
//* \brief Return CAN Error Counter Register Value
peter
parents:
diff changeset
  3154
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3155
__inline unsigned int AT91F_CAN_GetErrorCounter (
peter
parents:
diff changeset
  3156
	AT91PS_CAN pCAN // pointer to a CAN controller
peter
parents:
diff changeset
  3157
	)
peter
parents:
diff changeset
  3158
{
peter
parents:
diff changeset
  3159
	return pCAN->CAN_ECR;	
peter
parents:
diff changeset
  3160
}
peter
parents:
diff changeset
  3161
peter
parents:
diff changeset
  3162
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3163
//* \fn    AT91F_CAN_InitTransferRequest
peter
parents:
diff changeset
  3164
//* \brief Request for a transfer on the corresponding mailboxes
peter
parents:
diff changeset
  3165
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3166
__inline void AT91F_CAN_InitTransferRequest (
peter
parents:
diff changeset
  3167
	AT91PS_CAN pCAN, // pointer to a CAN controller
peter
parents:
diff changeset
  3168
    unsigned int transfer_cmd)
peter
parents:
diff changeset
  3169
{
peter
parents:
diff changeset
  3170
	pCAN->CAN_TCR = transfer_cmd;	
peter
parents:
diff changeset
  3171
}
peter
parents:
diff changeset
  3172
peter
parents:
diff changeset
  3173
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3174
//* \fn    AT91F_CAN_InitAbortRequest
peter
parents:
diff changeset
  3175
//* \brief Abort the corresponding mailboxes
peter
parents:
diff changeset
  3176
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3177
__inline void AT91F_CAN_InitAbortRequest (
peter
parents:
diff changeset
  3178
	AT91PS_CAN pCAN, // pointer to a CAN controller
peter
parents:
diff changeset
  3179
    unsigned int abort_cmd)
peter
parents:
diff changeset
  3180
{
peter
parents:
diff changeset
  3181
	pCAN->CAN_ACR = abort_cmd;	
peter
parents:
diff changeset
  3182
}
peter
parents:
diff changeset
  3183
peter
parents:
diff changeset
  3184
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3185
//* \fn    AT91F_CAN_CfgMessageModeReg
peter
parents:
diff changeset
  3186
//* \brief Program the Message Mode Register
peter
parents:
diff changeset
  3187
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3188
__inline void AT91F_CAN_CfgMessageModeReg (
peter
parents:
diff changeset
  3189
	AT91PS_CAN_MB	CAN_Mailbox, // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3190
    unsigned int mode)
peter
parents:
diff changeset
  3191
{
peter
parents:
diff changeset
  3192
	CAN_Mailbox->CAN_MB_MMR = mode;	
peter
parents:
diff changeset
  3193
}
peter
parents:
diff changeset
  3194
peter
parents:
diff changeset
  3195
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3196
//* \fn    AT91F_CAN_GetMessageModeReg
peter
parents:
diff changeset
  3197
//* \brief Return the Message Mode Register
peter
parents:
diff changeset
  3198
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3199
__inline unsigned int AT91F_CAN_GetMessageModeReg (
peter
parents:
diff changeset
  3200
	AT91PS_CAN_MB	CAN_Mailbox) // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3201
{
peter
parents:
diff changeset
  3202
	return CAN_Mailbox->CAN_MB_MMR;	
peter
parents:
diff changeset
  3203
}
peter
parents:
diff changeset
  3204
peter
parents:
diff changeset
  3205
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3206
//* \fn    AT91F_CAN_CfgMessageIDReg
peter
parents:
diff changeset
  3207
//* \brief Program the Message ID Register
peter
parents:
diff changeset
  3208
//* \brief Version == 0 for Standard messsage, Version == 1 for Extended
peter
parents:
diff changeset
  3209
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3210
__inline void AT91F_CAN_CfgMessageIDReg (
peter
parents:
diff changeset
  3211
	AT91PS_CAN_MB	CAN_Mailbox, // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3212
    unsigned int id,
peter
parents:
diff changeset
  3213
    unsigned char version)
peter
parents:
diff changeset
  3214
{
peter
parents:
diff changeset
  3215
	if(version==0)	// IDvA Standard Format
peter
parents:
diff changeset
  3216
		CAN_Mailbox->CAN_MB_MID = id<<18;
peter
parents:
diff changeset
  3217
	else	// IDvB Extended Format
peter
parents:
diff changeset
  3218
		CAN_Mailbox->CAN_MB_MID = id | (1<<29);	// set MIDE bit
peter
parents:
diff changeset
  3219
}
peter
parents:
diff changeset
  3220
peter
parents:
diff changeset
  3221
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3222
//* \fn    AT91F_CAN_GetMessageIDReg
peter
parents:
diff changeset
  3223
//* \brief Return the Message ID Register
peter
parents:
diff changeset
  3224
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3225
__inline unsigned int AT91F_CAN_GetMessageIDReg (
peter
parents:
diff changeset
  3226
	AT91PS_CAN_MB	CAN_Mailbox) // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3227
{
peter
parents:
diff changeset
  3228
	return CAN_Mailbox->CAN_MB_MID;
peter
parents:
diff changeset
  3229
}
peter
parents:
diff changeset
  3230
peter
parents:
diff changeset
  3231
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3232
//* \fn    AT91F_CAN_CfgMessageAcceptanceMaskReg
peter
parents:
diff changeset
  3233
//* \brief Program the Message Acceptance Mask Register
peter
parents:
diff changeset
  3234
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3235
__inline void AT91F_CAN_CfgMessageAcceptanceMaskReg (
peter
parents:
diff changeset
  3236
	AT91PS_CAN_MB	CAN_Mailbox, // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3237
    unsigned int mask)
peter
parents:
diff changeset
  3238
{
peter
parents:
diff changeset
  3239
	CAN_Mailbox->CAN_MB_MAM = mask;
peter
parents:
diff changeset
  3240
}
peter
parents:
diff changeset
  3241
peter
parents:
diff changeset
  3242
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3243
//* \fn    AT91F_CAN_GetMessageAcceptanceMaskReg
peter
parents:
diff changeset
  3244
//* \brief Return the Message Acceptance Mask Register
peter
parents:
diff changeset
  3245
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3246
__inline unsigned int AT91F_CAN_GetMessageAcceptanceMaskReg (
peter
parents:
diff changeset
  3247
	AT91PS_CAN_MB	CAN_Mailbox) // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3248
{
peter
parents:
diff changeset
  3249
	return CAN_Mailbox->CAN_MB_MAM;
peter
parents:
diff changeset
  3250
}
peter
parents:
diff changeset
  3251
peter
parents:
diff changeset
  3252
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3253
//* \fn    AT91F_CAN_GetFamilyID
peter
parents:
diff changeset
  3254
//* \brief Return the Message ID Register
peter
parents:
diff changeset
  3255
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3256
__inline unsigned int AT91F_CAN_GetFamilyID (
peter
parents:
diff changeset
  3257
	AT91PS_CAN_MB	CAN_Mailbox) // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3258
{
peter
parents:
diff changeset
  3259
	return CAN_Mailbox->CAN_MB_MFID;	
peter
parents:
diff changeset
  3260
}
peter
parents:
diff changeset
  3261
peter
parents:
diff changeset
  3262
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3263
//* \fn    AT91F_CAN_CfgMessageCtrlReg
peter
parents:
diff changeset
  3264
//* \brief Request and config for a transfer on the corresponding mailbox
peter
parents:
diff changeset
  3265
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3266
__inline void AT91F_CAN_CfgMessageCtrlReg (
peter
parents:
diff changeset
  3267
	AT91PS_CAN_MB	CAN_Mailbox, // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3268
    unsigned int message_ctrl_cmd)
peter
parents:
diff changeset
  3269
{
peter
parents:
diff changeset
  3270
	CAN_Mailbox->CAN_MB_MCR = message_ctrl_cmd;	
peter
parents:
diff changeset
  3271
}
peter
parents:
diff changeset
  3272
peter
parents:
diff changeset
  3273
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3274
//* \fn    AT91F_CAN_GetMessageStatus
peter
parents:
diff changeset
  3275
//* \brief Return CAN Mailbox Status
peter
parents:
diff changeset
  3276
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3277
__inline unsigned int AT91F_CAN_GetMessageStatus (
peter
parents:
diff changeset
  3278
	AT91PS_CAN_MB	CAN_Mailbox) // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3279
{
peter
parents:
diff changeset
  3280
	return CAN_Mailbox->CAN_MB_MSR;	
peter
parents:
diff changeset
  3281
}
peter
parents:
diff changeset
  3282
peter
parents:
diff changeset
  3283
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3284
//* \fn    AT91F_CAN_CfgMessageDataLow
peter
parents:
diff changeset
  3285
//* \brief Program data low value
peter
parents:
diff changeset
  3286
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3287
__inline void AT91F_CAN_CfgMessageDataLow (
peter
parents:
diff changeset
  3288
	AT91PS_CAN_MB	CAN_Mailbox, // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3289
    unsigned int data)
peter
parents:
diff changeset
  3290
{
peter
parents:
diff changeset
  3291
	CAN_Mailbox->CAN_MB_MDL = data;	
peter
parents:
diff changeset
  3292
}
peter
parents:
diff changeset
  3293
peter
parents:
diff changeset
  3294
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3295
//* \fn    AT91F_CAN_GetMessageDataLow
peter
parents:
diff changeset
  3296
//* \brief Return data low value
peter
parents:
diff changeset
  3297
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3298
__inline unsigned int AT91F_CAN_GetMessageDataLow (
peter
parents:
diff changeset
  3299
	AT91PS_CAN_MB	CAN_Mailbox) // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3300
{
peter
parents:
diff changeset
  3301
	return CAN_Mailbox->CAN_MB_MDL;	
peter
parents:
diff changeset
  3302
}
peter
parents:
diff changeset
  3303
peter
parents:
diff changeset
  3304
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3305
//* \fn    AT91F_CAN_CfgMessageDataHigh
peter
parents:
diff changeset
  3306
//* \brief Program data high value
peter
parents:
diff changeset
  3307
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3308
__inline void AT91F_CAN_CfgMessageDataHigh (
peter
parents:
diff changeset
  3309
	AT91PS_CAN_MB	CAN_Mailbox, // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3310
    unsigned int data)
peter
parents:
diff changeset
  3311
{
peter
parents:
diff changeset
  3312
	CAN_Mailbox->CAN_MB_MDH = data;	
peter
parents:
diff changeset
  3313
}
peter
parents:
diff changeset
  3314
peter
parents:
diff changeset
  3315
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3316
//* \fn    AT91F_CAN_GetMessageDataHigh
peter
parents:
diff changeset
  3317
//* \brief Return data high value
peter
parents:
diff changeset
  3318
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3319
__inline unsigned int AT91F_CAN_GetMessageDataHigh (
peter
parents:
diff changeset
  3320
	AT91PS_CAN_MB	CAN_Mailbox) // pointer to a CAN Mailbox
peter
parents:
diff changeset
  3321
{
peter
parents:
diff changeset
  3322
	return CAN_Mailbox->CAN_MB_MDH;	
peter
parents:
diff changeset
  3323
}
peter
parents:
diff changeset
  3324
peter
parents:
diff changeset
  3325
/* *****************************************************************************
peter
parents:
diff changeset
  3326
                SOFTWARE API FOR ADC
peter
parents:
diff changeset
  3327
   ***************************************************************************** */
peter
parents:
diff changeset
  3328
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3329
//* \fn    AT91F_ADC_EnableIt
peter
parents:
diff changeset
  3330
//* \brief Enable ADC interrupt
peter
parents:
diff changeset
  3331
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3332
__inline void AT91F_ADC_EnableIt (
peter
parents:
diff changeset
  3333
	AT91PS_ADC pADC,     // pointer to a ADC controller
peter
parents:
diff changeset
  3334
	unsigned int flag)   // IT to be enabled
peter
parents:
diff changeset
  3335
{
peter
parents:
diff changeset
  3336
	//* Write to the IER register
peter
parents:
diff changeset
  3337
	pADC->ADC_IER = flag;
peter
parents:
diff changeset
  3338
}
peter
parents:
diff changeset
  3339
peter
parents:
diff changeset
  3340
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3341
//* \fn    AT91F_ADC_DisableIt
peter
parents:
diff changeset
  3342
//* \brief Disable ADC interrupt
peter
parents:
diff changeset
  3343
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3344
__inline void AT91F_ADC_DisableIt (
peter
parents:
diff changeset
  3345
	AT91PS_ADC pADC, // pointer to a ADC controller
peter
parents:
diff changeset
  3346
	unsigned int flag) // IT to be disabled
peter
parents:
diff changeset
  3347
{
peter
parents:
diff changeset
  3348
	//* Write to the IDR register
peter
parents:
diff changeset
  3349
	pADC->ADC_IDR = flag;
peter
parents:
diff changeset
  3350
}
peter
parents:
diff changeset
  3351
peter
parents:
diff changeset
  3352
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3353
//* \fn    AT91F_ADC_GetStatus
peter
parents:
diff changeset
  3354
//* \brief Return ADC Interrupt Status
peter
parents:
diff changeset
  3355
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3356
__inline unsigned int AT91F_ADC_GetStatus( // \return ADC Interrupt Status
peter
parents:
diff changeset
  3357
	AT91PS_ADC pADC) // pointer to a ADC controller
peter
parents:
diff changeset
  3358
{
peter
parents:
diff changeset
  3359
	return pADC->ADC_SR;
peter
parents:
diff changeset
  3360
}
peter
parents:
diff changeset
  3361
peter
parents:
diff changeset
  3362
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3363
//* \fn    AT91F_ADC_GetInterruptMaskStatus
peter
parents:
diff changeset
  3364
//* \brief Return ADC Interrupt Mask Status
peter
parents:
diff changeset
  3365
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3366
__inline unsigned int AT91F_ADC_GetInterruptMaskStatus( // \return ADC Interrupt Mask Status
peter
parents:
diff changeset
  3367
	AT91PS_ADC pADC) // pointer to a ADC controller
peter
parents:
diff changeset
  3368
{
peter
parents:
diff changeset
  3369
	return pADC->ADC_IMR;
peter
parents:
diff changeset
  3370
}
peter
parents:
diff changeset
  3371
peter
parents:
diff changeset
  3372
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3373
//* \fn    AT91F_ADC_IsInterruptMasked
peter
parents:
diff changeset
  3374
//* \brief Test if ADC Interrupt is Masked
peter
parents:
diff changeset
  3375
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3376
__inline unsigned int AT91F_ADC_IsInterruptMasked(
peter
parents:
diff changeset
  3377
        AT91PS_ADC pADC,   // \arg  pointer to a ADC controller
peter
parents:
diff changeset
  3378
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  3379
{
peter
parents:
diff changeset
  3380
	return (AT91F_ADC_GetInterruptMaskStatus(pADC) & flag);
peter
parents:
diff changeset
  3381
}
peter
parents:
diff changeset
  3382
peter
parents:
diff changeset
  3383
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3384
//* \fn    AT91F_ADC_IsStatusSet
peter
parents:
diff changeset
  3385
//* \brief Test if ADC Status is Set
peter
parents:
diff changeset
  3386
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3387
__inline unsigned int AT91F_ADC_IsStatusSet(
peter
parents:
diff changeset
  3388
        AT91PS_ADC pADC,   // \arg  pointer to a ADC controller
peter
parents:
diff changeset
  3389
        unsigned int flag) // \arg  flag to be tested
peter
parents:
diff changeset
  3390
{
peter
parents:
diff changeset
  3391
	return (AT91F_ADC_GetStatus(pADC) & flag);
peter
parents:
diff changeset
  3392
}
peter
parents:
diff changeset
  3393
peter
parents:
diff changeset
  3394
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3395
//* \fn    AT91F_ADC_CfgModeReg
peter
parents:
diff changeset
  3396
//* \brief Configure the Mode Register of the ADC controller
peter
parents:
diff changeset
  3397
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3398
__inline void AT91F_ADC_CfgModeReg (
peter
parents:
diff changeset
  3399
	AT91PS_ADC pADC, // pointer to a ADC controller
peter
parents:
diff changeset
  3400
	unsigned int mode)        // mode register
peter
parents:
diff changeset
  3401
{
peter
parents:
diff changeset
  3402
	//* Write to the MR register
peter
parents:
diff changeset
  3403
	pADC->ADC_MR = mode;
peter
parents:
diff changeset
  3404
}
peter
parents:
diff changeset
  3405
peter
parents:
diff changeset
  3406
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3407
//* \fn    AT91F_ADC_GetModeReg
peter
parents:
diff changeset
  3408
//* \brief Return the Mode Register of the ADC controller value
peter
parents:
diff changeset
  3409
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3410
__inline unsigned int AT91F_ADC_GetModeReg (
peter
parents:
diff changeset
  3411
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3412
	)
peter
parents:
diff changeset
  3413
{
peter
parents:
diff changeset
  3414
	return pADC->ADC_MR;	
peter
parents:
diff changeset
  3415
}
peter
parents:
diff changeset
  3416
peter
parents:
diff changeset
  3417
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3418
//* \fn    AT91F_ADC_CfgTimings
peter
parents:
diff changeset
  3419
//* \brief Configure the different necessary timings of the ADC controller
peter
parents:
diff changeset
  3420
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3421
__inline void AT91F_ADC_CfgTimings (
peter
parents:
diff changeset
  3422
	AT91PS_ADC pADC, // pointer to a ADC controller
peter
parents:
diff changeset
  3423
	unsigned int mck_clock, // in MHz
peter
parents:
diff changeset
  3424
	unsigned int adc_clock, // in MHz
peter
parents:
diff changeset
  3425
	unsigned int startup_time, // in us
peter
parents:
diff changeset
  3426
	unsigned int sample_and_hold_time)	// in ns
peter
parents:
diff changeset
  3427
{
peter
parents:
diff changeset
  3428
	unsigned int prescal,startup,shtim;
peter
parents:
diff changeset
  3429
	
peter
parents:
diff changeset
  3430
	prescal = mck_clock/(2*adc_clock) - 1;
peter
parents:
diff changeset
  3431
	startup = adc_clock*startup_time/8 - 1;
peter
parents:
diff changeset
  3432
	shtim = adc_clock*sample_and_hold_time/1000 - 1;
peter
parents:
diff changeset
  3433
	
peter
parents:
diff changeset
  3434
	//* Write to the MR register
peter
parents:
diff changeset
  3435
	pADC->ADC_MR = ( (prescal<<8) & AT91C_ADC_PRESCAL) | ( (startup<<16) & AT91C_ADC_STARTUP) | ( (shtim<<24) & AT91C_ADC_SHTIM);
peter
parents:
diff changeset
  3436
}
peter
parents:
diff changeset
  3437
peter
parents:
diff changeset
  3438
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3439
//* \fn    AT91F_ADC_EnableChannel
peter
parents:
diff changeset
  3440
//* \brief Return ADC Timer Register Value
peter
parents:
diff changeset
  3441
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3442
__inline void AT91F_ADC_EnableChannel (
peter
parents:
diff changeset
  3443
	AT91PS_ADC pADC, // pointer to a ADC controller
peter
parents:
diff changeset
  3444
	unsigned int channel)        // mode register
peter
parents:
diff changeset
  3445
{
peter
parents:
diff changeset
  3446
	//* Write to the CHER register
peter
parents:
diff changeset
  3447
	pADC->ADC_CHER = channel;
peter
parents:
diff changeset
  3448
}
peter
parents:
diff changeset
  3449
peter
parents:
diff changeset
  3450
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3451
//* \fn    AT91F_ADC_DisableChannel
peter
parents:
diff changeset
  3452
//* \brief Return ADC Timer Register Value
peter
parents:
diff changeset
  3453
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3454
__inline void AT91F_ADC_DisableChannel (
peter
parents:
diff changeset
  3455
	AT91PS_ADC pADC, // pointer to a ADC controller
peter
parents:
diff changeset
  3456
	unsigned int channel)        // mode register
peter
parents:
diff changeset
  3457
{
peter
parents:
diff changeset
  3458
	//* Write to the CHDR register
peter
parents:
diff changeset
  3459
	pADC->ADC_CHDR = channel;
peter
parents:
diff changeset
  3460
}
peter
parents:
diff changeset
  3461
peter
parents:
diff changeset
  3462
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3463
//* \fn    AT91F_ADC_GetChannelStatus
peter
parents:
diff changeset
  3464
//* \brief Return ADC Timer Register Value
peter
parents:
diff changeset
  3465
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3466
__inline unsigned int AT91F_ADC_GetChannelStatus (
peter
parents:
diff changeset
  3467
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3468
	)
peter
parents:
diff changeset
  3469
{
peter
parents:
diff changeset
  3470
	return pADC->ADC_CHSR;	
peter
parents:
diff changeset
  3471
}
peter
parents:
diff changeset
  3472
peter
parents:
diff changeset
  3473
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3474
//* \fn    AT91F_ADC_StartConversion
peter
parents:
diff changeset
  3475
//* \brief Software request for a analog to digital conversion
peter
parents:
diff changeset
  3476
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3477
__inline void AT91F_ADC_StartConversion (
peter
parents:
diff changeset
  3478
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3479
	)
peter
parents:
diff changeset
  3480
{
peter
parents:
diff changeset
  3481
	pADC->ADC_CR = AT91C_ADC_START;	
peter
parents:
diff changeset
  3482
}
peter
parents:
diff changeset
  3483
peter
parents:
diff changeset
  3484
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3485
//* \fn    AT91F_ADC_SoftReset
peter
parents:
diff changeset
  3486
//* \brief Software reset
peter
parents:
diff changeset
  3487
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3488
__inline void AT91F_ADC_SoftReset (
peter
parents:
diff changeset
  3489
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3490
	)
peter
parents:
diff changeset
  3491
{
peter
parents:
diff changeset
  3492
	pADC->ADC_CR = AT91C_ADC_SWRST;	
peter
parents:
diff changeset
  3493
}
peter
parents:
diff changeset
  3494
peter
parents:
diff changeset
  3495
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3496
//* \fn    AT91F_ADC_GetLastConvertedData
peter
parents:
diff changeset
  3497
//* \brief Return the Last Converted Data
peter
parents:
diff changeset
  3498
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3499
__inline unsigned int AT91F_ADC_GetLastConvertedData (
peter
parents:
diff changeset
  3500
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3501
	)
peter
parents:
diff changeset
  3502
{
peter
parents:
diff changeset
  3503
	return pADC->ADC_LCDR;	
peter
parents:
diff changeset
  3504
}
peter
parents:
diff changeset
  3505
peter
parents:
diff changeset
  3506
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3507
//* \fn    AT91F_ADC_GetConvertedDataCH0
peter
parents:
diff changeset
  3508
//* \brief Return the Channel 0 Converted Data
peter
parents:
diff changeset
  3509
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3510
__inline unsigned int AT91F_ADC_GetConvertedDataCH0 (
peter
parents:
diff changeset
  3511
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3512
	)
peter
parents:
diff changeset
  3513
{
peter
parents:
diff changeset
  3514
	return pADC->ADC_CDR0;	
peter
parents:
diff changeset
  3515
}
peter
parents:
diff changeset
  3516
peter
parents:
diff changeset
  3517
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3518
//* \fn    AT91F_ADC_GetConvertedDataCH1
peter
parents:
diff changeset
  3519
//* \brief Return the Channel 1 Converted Data
peter
parents:
diff changeset
  3520
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3521
__inline unsigned int AT91F_ADC_GetConvertedDataCH1 (
peter
parents:
diff changeset
  3522
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3523
	)
peter
parents:
diff changeset
  3524
{
peter
parents:
diff changeset
  3525
	return pADC->ADC_CDR1;	
peter
parents:
diff changeset
  3526
}
peter
parents:
diff changeset
  3527
peter
parents:
diff changeset
  3528
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3529
//* \fn    AT91F_ADC_GetConvertedDataCH2
peter
parents:
diff changeset
  3530
//* \brief Return the Channel 2 Converted Data
peter
parents:
diff changeset
  3531
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3532
__inline unsigned int AT91F_ADC_GetConvertedDataCH2 (
peter
parents:
diff changeset
  3533
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3534
	)
peter
parents:
diff changeset
  3535
{
peter
parents:
diff changeset
  3536
	return pADC->ADC_CDR2;	
peter
parents:
diff changeset
  3537
}
peter
parents:
diff changeset
  3538
peter
parents:
diff changeset
  3539
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3540
//* \fn    AT91F_ADC_GetConvertedDataCH3
peter
parents:
diff changeset
  3541
//* \brief Return the Channel 3 Converted Data
peter
parents:
diff changeset
  3542
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3543
__inline unsigned int AT91F_ADC_GetConvertedDataCH3 (
peter
parents:
diff changeset
  3544
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3545
	)
peter
parents:
diff changeset
  3546
{
peter
parents:
diff changeset
  3547
	return pADC->ADC_CDR3;	
peter
parents:
diff changeset
  3548
}
peter
parents:
diff changeset
  3549
peter
parents:
diff changeset
  3550
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3551
//* \fn    AT91F_ADC_GetConvertedDataCH4
peter
parents:
diff changeset
  3552
//* \brief Return the Channel 4 Converted Data
peter
parents:
diff changeset
  3553
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3554
__inline unsigned int AT91F_ADC_GetConvertedDataCH4 (
peter
parents:
diff changeset
  3555
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3556
	)
peter
parents:
diff changeset
  3557
{
peter
parents:
diff changeset
  3558
	return pADC->ADC_CDR4;	
peter
parents:
diff changeset
  3559
}
peter
parents:
diff changeset
  3560
peter
parents:
diff changeset
  3561
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3562
//* \fn    AT91F_ADC_GetConvertedDataCH5
peter
parents:
diff changeset
  3563
//* \brief Return the Channel 5 Converted Data
peter
parents:
diff changeset
  3564
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3565
__inline unsigned int AT91F_ADC_GetConvertedDataCH5 (
peter
parents:
diff changeset
  3566
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3567
	)
peter
parents:
diff changeset
  3568
{
peter
parents:
diff changeset
  3569
	return pADC->ADC_CDR5;	
peter
parents:
diff changeset
  3570
}
peter
parents:
diff changeset
  3571
peter
parents:
diff changeset
  3572
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3573
//* \fn    AT91F_ADC_GetConvertedDataCH6
peter
parents:
diff changeset
  3574
//* \brief Return the Channel 6 Converted Data
peter
parents:
diff changeset
  3575
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3576
__inline unsigned int AT91F_ADC_GetConvertedDataCH6 (
peter
parents:
diff changeset
  3577
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3578
	)
peter
parents:
diff changeset
  3579
{
peter
parents:
diff changeset
  3580
	return pADC->ADC_CDR6;	
peter
parents:
diff changeset
  3581
}
peter
parents:
diff changeset
  3582
peter
parents:
diff changeset
  3583
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3584
//* \fn    AT91F_ADC_GetConvertedDataCH7
peter
parents:
diff changeset
  3585
//* \brief Return the Channel 7 Converted Data
peter
parents:
diff changeset
  3586
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3587
__inline unsigned int AT91F_ADC_GetConvertedDataCH7 (
peter
parents:
diff changeset
  3588
	AT91PS_ADC pADC // pointer to a ADC controller
peter
parents:
diff changeset
  3589
	)
peter
parents:
diff changeset
  3590
{
peter
parents:
diff changeset
  3591
	return pADC->ADC_CDR7;	
peter
parents:
diff changeset
  3592
}
peter
parents:
diff changeset
  3593
peter
parents:
diff changeset
  3594
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3595
//* \fn    AT91F_DBGU_CfgPMC
peter
parents:
diff changeset
  3596
//* \brief Enable Peripheral clock in PMC for  DBGU
peter
parents:
diff changeset
  3597
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3598
__inline void AT91F_DBGU_CfgPMC (void)
peter
parents:
diff changeset
  3599
{
peter
parents:
diff changeset
  3600
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3601
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3602
		((unsigned int) 1 << AT91C_ID_SYS));
peter
parents:
diff changeset
  3603
}
peter
parents:
diff changeset
  3604
peter
parents:
diff changeset
  3605
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3606
//* \fn    AT91F_DBGU_CfgPIO
peter
parents:
diff changeset
  3607
//* \brief Configure PIO controllers to drive DBGU signals
peter
parents:
diff changeset
  3608
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3609
__inline void AT91F_DBGU_CfgPIO (void)
peter
parents:
diff changeset
  3610
{
peter
parents:
diff changeset
  3611
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3612
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3613
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3614
		((unsigned int) AT91C_PA27_DRXD    ) |
peter
parents:
diff changeset
  3615
		((unsigned int) AT91C_PA28_DTXD    ), // Peripheral A
peter
parents:
diff changeset
  3616
		0); // Peripheral B
peter
parents:
diff changeset
  3617
}
peter
parents:
diff changeset
  3618
peter
parents:
diff changeset
  3619
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3620
//* \fn    AT91F_PMC_CfgPMC
peter
parents:
diff changeset
  3621
//* \brief Enable Peripheral clock in PMC for  PMC
peter
parents:
diff changeset
  3622
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3623
__inline void AT91F_PMC_CfgPMC (void)
peter
parents:
diff changeset
  3624
{
peter
parents:
diff changeset
  3625
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3626
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3627
		((unsigned int) 1 << AT91C_ID_SYS));
peter
parents:
diff changeset
  3628
}
peter
parents:
diff changeset
  3629
peter
parents:
diff changeset
  3630
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3631
//* \fn    AT91F_PMC_CfgPIO
peter
parents:
diff changeset
  3632
//* \brief Configure PIO controllers to drive PMC signals
peter
parents:
diff changeset
  3633
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3634
__inline void AT91F_PMC_CfgPIO (void)
peter
parents:
diff changeset
  3635
{
peter
parents:
diff changeset
  3636
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3637
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3638
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3639
		((unsigned int) AT91C_PB30_PCK2    ) |
peter
parents:
diff changeset
  3640
		((unsigned int) AT91C_PB29_PCK1    ), // Peripheral A
peter
parents:
diff changeset
  3641
		((unsigned int) AT91C_PB20_PCK0    ) |
peter
parents:
diff changeset
  3642
		((unsigned int) AT91C_PB0_PCK0    ) |
peter
parents:
diff changeset
  3643
		((unsigned int) AT91C_PB22_PCK2    ) |
peter
parents:
diff changeset
  3644
		((unsigned int) AT91C_PB21_PCK1    )); // Peripheral B
peter
parents:
diff changeset
  3645
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3646
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3647
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3648
		0, // Peripheral A
peter
parents:
diff changeset
  3649
		((unsigned int) AT91C_PA30_PCK2    ) |
peter
parents:
diff changeset
  3650
		((unsigned int) AT91C_PA13_PCK1    ) |
peter
parents:
diff changeset
  3651
		((unsigned int) AT91C_PA27_PCK3    )); // Peripheral B
peter
parents:
diff changeset
  3652
}
peter
parents:
diff changeset
  3653
peter
parents:
diff changeset
  3654
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3655
//* \fn    AT91F_VREG_CfgPMC
peter
parents:
diff changeset
  3656
//* \brief Enable Peripheral clock in PMC for  VREG
peter
parents:
diff changeset
  3657
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3658
__inline void AT91F_VREG_CfgPMC (void)
peter
parents:
diff changeset
  3659
{
peter
parents:
diff changeset
  3660
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3661
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3662
		((unsigned int) 1 << AT91C_ID_SYS));
peter
parents:
diff changeset
  3663
}
peter
parents:
diff changeset
  3664
peter
parents:
diff changeset
  3665
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3666
//* \fn    AT91F_RSTC_CfgPMC
peter
parents:
diff changeset
  3667
//* \brief Enable Peripheral clock in PMC for  RSTC
peter
parents:
diff changeset
  3668
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3669
__inline void AT91F_RSTC_CfgPMC (void)
peter
parents:
diff changeset
  3670
{
peter
parents:
diff changeset
  3671
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3672
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3673
		((unsigned int) 1 << AT91C_ID_SYS));
peter
parents:
diff changeset
  3674
}
peter
parents:
diff changeset
  3675
peter
parents:
diff changeset
  3676
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3677
//* \fn    AT91F_SSC_CfgPMC
peter
parents:
diff changeset
  3678
//* \brief Enable Peripheral clock in PMC for  SSC
peter
parents:
diff changeset
  3679
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3680
__inline void AT91F_SSC_CfgPMC (void)
peter
parents:
diff changeset
  3681
{
peter
parents:
diff changeset
  3682
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3683
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3684
		((unsigned int) 1 << AT91C_ID_SSC));
peter
parents:
diff changeset
  3685
}
peter
parents:
diff changeset
  3686
peter
parents:
diff changeset
  3687
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3688
//* \fn    AT91F_SSC_CfgPIO
peter
parents:
diff changeset
  3689
//* \brief Configure PIO controllers to drive SSC signals
peter
parents:
diff changeset
  3690
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3691
__inline void AT91F_SSC_CfgPIO (void)
peter
parents:
diff changeset
  3692
{
peter
parents:
diff changeset
  3693
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3694
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3695
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3696
		((unsigned int) AT91C_PA25_RK      ) |
peter
parents:
diff changeset
  3697
		((unsigned int) AT91C_PA22_TK      ) |
peter
parents:
diff changeset
  3698
		((unsigned int) AT91C_PA21_TF      ) |
peter
parents:
diff changeset
  3699
		((unsigned int) AT91C_PA24_RD      ) |
peter
parents:
diff changeset
  3700
		((unsigned int) AT91C_PA26_RF      ) |
peter
parents:
diff changeset
  3701
		((unsigned int) AT91C_PA23_TD      ), // Peripheral A
peter
parents:
diff changeset
  3702
		0); // Peripheral B
peter
parents:
diff changeset
  3703
}
peter
parents:
diff changeset
  3704
peter
parents:
diff changeset
  3705
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3706
//* \fn    AT91F_WDTC_CfgPMC
peter
parents:
diff changeset
  3707
//* \brief Enable Peripheral clock in PMC for  WDTC
peter
parents:
diff changeset
  3708
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3709
__inline void AT91F_WDTC_CfgPMC (void)
peter
parents:
diff changeset
  3710
{
peter
parents:
diff changeset
  3711
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3712
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3713
		((unsigned int) 1 << AT91C_ID_SYS));
peter
parents:
diff changeset
  3714
}
peter
parents:
diff changeset
  3715
peter
parents:
diff changeset
  3716
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3717
//* \fn    AT91F_US1_CfgPMC
peter
parents:
diff changeset
  3718
//* \brief Enable Peripheral clock in PMC for  US1
peter
parents:
diff changeset
  3719
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3720
__inline void AT91F_US1_CfgPMC (void)
peter
parents:
diff changeset
  3721
{
peter
parents:
diff changeset
  3722
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3723
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3724
		((unsigned int) 1 << AT91C_ID_US1));
peter
parents:
diff changeset
  3725
}
peter
parents:
diff changeset
  3726
peter
parents:
diff changeset
  3727
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3728
//* \fn    AT91F_US1_CfgPIO
peter
parents:
diff changeset
  3729
//* \brief Configure PIO controllers to drive US1 signals
peter
parents:
diff changeset
  3730
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3731
__inline void AT91F_US1_CfgPIO (void)
peter
parents:
diff changeset
  3732
{
peter
parents:
diff changeset
  3733
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3734
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3735
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3736
		0, // Peripheral A
peter
parents:
diff changeset
  3737
		((unsigned int) AT91C_PB26_RI1     ) |
peter
parents:
diff changeset
  3738
		((unsigned int) AT91C_PB24_DSR1    ) |
peter
parents:
diff changeset
  3739
		((unsigned int) AT91C_PB23_DCD1    ) |
peter
parents:
diff changeset
  3740
		((unsigned int) AT91C_PB25_DTR1    )); // Peripheral B
peter
parents:
diff changeset
  3741
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3742
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3743
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3744
		((unsigned int) AT91C_PA7_SCK1    ) |
peter
parents:
diff changeset
  3745
		((unsigned int) AT91C_PA8_RTS1    ) |
peter
parents:
diff changeset
  3746
		((unsigned int) AT91C_PA6_TXD1    ) |
peter
parents:
diff changeset
  3747
		((unsigned int) AT91C_PA5_RXD1    ) |
peter
parents:
diff changeset
  3748
		((unsigned int) AT91C_PA9_CTS1    ), // Peripheral A
peter
parents:
diff changeset
  3749
		0); // Peripheral B
peter
parents:
diff changeset
  3750
}
peter
parents:
diff changeset
  3751
peter
parents:
diff changeset
  3752
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3753
//* \fn    AT91F_US0_CfgPMC
peter
parents:
diff changeset
  3754
//* \brief Enable Peripheral clock in PMC for  US0
peter
parents:
diff changeset
  3755
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3756
__inline void AT91F_US0_CfgPMC (void)
peter
parents:
diff changeset
  3757
{
peter
parents:
diff changeset
  3758
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3759
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3760
		((unsigned int) 1 << AT91C_ID_US0));
peter
parents:
diff changeset
  3761
}
peter
parents:
diff changeset
  3762
peter
parents:
diff changeset
  3763
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3764
//* \fn    AT91F_US0_CfgPIO
peter
parents:
diff changeset
  3765
//* \brief Configure PIO controllers to drive US0 signals
peter
parents:
diff changeset
  3766
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3767
__inline void AT91F_US0_CfgPIO (void)
peter
parents:
diff changeset
  3768
{
peter
parents:
diff changeset
  3769
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3770
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3771
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3772
		((unsigned int) AT91C_PA0_RXD0    ) |
peter
parents:
diff changeset
  3773
		((unsigned int) AT91C_PA4_CTS0    ) |
peter
parents:
diff changeset
  3774
		((unsigned int) AT91C_PA3_RTS0    ) |
peter
parents:
diff changeset
  3775
		((unsigned int) AT91C_PA2_SCK0    ) |
peter
parents:
diff changeset
  3776
		((unsigned int) AT91C_PA1_TXD0    ), // Peripheral A
peter
parents:
diff changeset
  3777
		0); // Peripheral B
peter
parents:
diff changeset
  3778
}
peter
parents:
diff changeset
  3779
peter
parents:
diff changeset
  3780
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3781
//* \fn    AT91F_SPI1_CfgPMC
peter
parents:
diff changeset
  3782
//* \brief Enable Peripheral clock in PMC for  SPI1
peter
parents:
diff changeset
  3783
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3784
__inline void AT91F_SPI1_CfgPMC (void)
peter
parents:
diff changeset
  3785
{
peter
parents:
diff changeset
  3786
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3787
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3788
		((unsigned int) 1 << AT91C_ID_SPI1));
peter
parents:
diff changeset
  3789
}
peter
parents:
diff changeset
  3790
peter
parents:
diff changeset
  3791
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3792
//* \fn    AT91F_SPI1_CfgPIO
peter
parents:
diff changeset
  3793
//* \brief Configure PIO controllers to drive SPI1 signals
peter
parents:
diff changeset
  3794
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3795
__inline void AT91F_SPI1_CfgPIO (void)
peter
parents:
diff changeset
  3796
{
peter
parents:
diff changeset
  3797
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3798
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3799
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3800
		0, // Peripheral A
peter
parents:
diff changeset
  3801
		((unsigned int) AT91C_PB11_SPI1_NPCS2) |
peter
parents:
diff changeset
  3802
		((unsigned int) AT91C_PB10_SPI1_NPCS1) |
peter
parents:
diff changeset
  3803
		((unsigned int) AT91C_PB16_SPI1_NPCS3)); // Peripheral B
peter
parents:
diff changeset
  3804
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3805
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3806
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3807
		0, // Peripheral A
peter
parents:
diff changeset
  3808
		((unsigned int) AT91C_PA22_SPI1_SPCK) |
peter
parents:
diff changeset
  3809
		((unsigned int) AT91C_PA3_SPI1_NPCS2) |
peter
parents:
diff changeset
  3810
		((unsigned int) AT91C_PA26_SPI1_NPCS2) |
peter
parents:
diff changeset
  3811
		((unsigned int) AT91C_PA25_SPI1_NPCS1) |
peter
parents:
diff changeset
  3812
		((unsigned int) AT91C_PA2_SPI1_NPCS1) |
peter
parents:
diff changeset
  3813
		((unsigned int) AT91C_PA24_SPI1_MISO) |
peter
parents:
diff changeset
  3814
		((unsigned int) AT91C_PA4_SPI1_NPCS3) |
peter
parents:
diff changeset
  3815
		((unsigned int) AT91C_PA29_SPI1_NPCS3) |
peter
parents:
diff changeset
  3816
		((unsigned int) AT91C_PA21_SPI1_NPCS0) |
peter
parents:
diff changeset
  3817
		((unsigned int) AT91C_PA23_SPI1_MOSI)); // Peripheral B
peter
parents:
diff changeset
  3818
}
peter
parents:
diff changeset
  3819
peter
parents:
diff changeset
  3820
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3821
//* \fn    AT91F_SPI0_CfgPMC
peter
parents:
diff changeset
  3822
//* \brief Enable Peripheral clock in PMC for  SPI0
peter
parents:
diff changeset
  3823
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3824
__inline void AT91F_SPI0_CfgPMC (void)
peter
parents:
diff changeset
  3825
{
peter
parents:
diff changeset
  3826
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3827
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3828
		((unsigned int) 1 << AT91C_ID_SPI0));
peter
parents:
diff changeset
  3829
}
peter
parents:
diff changeset
  3830
peter
parents:
diff changeset
  3831
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3832
//* \fn    AT91F_SPI0_CfgPIO
peter
parents:
diff changeset
  3833
//* \brief Configure PIO controllers to drive SPI0 signals
peter
parents:
diff changeset
  3834
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3835
__inline void AT91F_SPI0_CfgPIO (void)
peter
parents:
diff changeset
  3836
{
peter
parents:
diff changeset
  3837
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3838
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3839
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3840
		0, // Peripheral A
peter
parents:
diff changeset
  3841
		((unsigned int) AT91C_PB13_SPI0_NPCS1) |
peter
parents:
diff changeset
  3842
		((unsigned int) AT91C_PB14_SPI0_NPCS2) |
peter
parents:
diff changeset
  3843
		((unsigned int) AT91C_PB17_SPI0_NPCS3)); // Peripheral B
peter
parents:
diff changeset
  3844
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3845
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3846
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3847
		((unsigned int) AT91C_PA16_SPI0_MISO) |
peter
parents:
diff changeset
  3848
		((unsigned int) AT91C_PA13_SPI0_NPCS1) |
peter
parents:
diff changeset
  3849
		((unsigned int) AT91C_PA14_SPI0_NPCS2) |
peter
parents:
diff changeset
  3850
		((unsigned int) AT91C_PA12_SPI0_NPCS0) |
peter
parents:
diff changeset
  3851
		((unsigned int) AT91C_PA17_SPI0_MOSI) |
peter
parents:
diff changeset
  3852
		((unsigned int) AT91C_PA15_SPI0_NPCS3) |
peter
parents:
diff changeset
  3853
		((unsigned int) AT91C_PA18_SPI0_SPCK), // Peripheral A
peter
parents:
diff changeset
  3854
		((unsigned int) AT91C_PA7_SPI0_NPCS1) |
peter
parents:
diff changeset
  3855
		((unsigned int) AT91C_PA8_SPI0_NPCS2) |
peter
parents:
diff changeset
  3856
		((unsigned int) AT91C_PA9_SPI0_NPCS3)); // Peripheral B
peter
parents:
diff changeset
  3857
}
peter
parents:
diff changeset
  3858
peter
parents:
diff changeset
  3859
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3860
//* \fn    AT91F_PITC_CfgPMC
peter
parents:
diff changeset
  3861
//* \brief Enable Peripheral clock in PMC for  PITC
peter
parents:
diff changeset
  3862
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3863
__inline void AT91F_PITC_CfgPMC (void)
peter
parents:
diff changeset
  3864
{
peter
parents:
diff changeset
  3865
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3866
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3867
		((unsigned int) 1 << AT91C_ID_SYS));
peter
parents:
diff changeset
  3868
}
peter
parents:
diff changeset
  3869
peter
parents:
diff changeset
  3870
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3871
//* \fn    AT91F_AIC_CfgPMC
peter
parents:
diff changeset
  3872
//* \brief Enable Peripheral clock in PMC for  AIC
peter
parents:
diff changeset
  3873
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3874
__inline void AT91F_AIC_CfgPMC (void)
peter
parents:
diff changeset
  3875
{
peter
parents:
diff changeset
  3876
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3877
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3878
		((unsigned int) 1 << AT91C_ID_FIQ) |
peter
parents:
diff changeset
  3879
		((unsigned int) 1 << AT91C_ID_IRQ0) |
peter
parents:
diff changeset
  3880
		((unsigned int) 1 << AT91C_ID_IRQ1));
peter
parents:
diff changeset
  3881
}
peter
parents:
diff changeset
  3882
peter
parents:
diff changeset
  3883
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3884
//* \fn    AT91F_AIC_CfgPIO
peter
parents:
diff changeset
  3885
//* \brief Configure PIO controllers to drive AIC signals
peter
parents:
diff changeset
  3886
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3887
__inline void AT91F_AIC_CfgPIO (void)
peter
parents:
diff changeset
  3888
{
peter
parents:
diff changeset
  3889
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3890
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3891
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3892
		((unsigned int) AT91C_PA30_IRQ0    ) |
peter
parents:
diff changeset
  3893
		((unsigned int) AT91C_PA29_FIQ     ), // Peripheral A
peter
parents:
diff changeset
  3894
		((unsigned int) AT91C_PA14_IRQ1    )); // Peripheral B
peter
parents:
diff changeset
  3895
}
peter
parents:
diff changeset
  3896
peter
parents:
diff changeset
  3897
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3898
//* \fn    AT91F_TWI_CfgPMC
peter
parents:
diff changeset
  3899
//* \brief Enable Peripheral clock in PMC for  TWI
peter
parents:
diff changeset
  3900
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3901
__inline void AT91F_TWI_CfgPMC (void)
peter
parents:
diff changeset
  3902
{
peter
parents:
diff changeset
  3903
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3904
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3905
		((unsigned int) 1 << AT91C_ID_TWI));
peter
parents:
diff changeset
  3906
}
peter
parents:
diff changeset
  3907
peter
parents:
diff changeset
  3908
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3909
//* \fn    AT91F_TWI_CfgPIO
peter
parents:
diff changeset
  3910
//* \brief Configure PIO controllers to drive TWI signals
peter
parents:
diff changeset
  3911
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3912
__inline void AT91F_TWI_CfgPIO (void)
peter
parents:
diff changeset
  3913
{
peter
parents:
diff changeset
  3914
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3915
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3916
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  3917
		((unsigned int) AT91C_PA11_TWCK    ) |
peter
parents:
diff changeset
  3918
		((unsigned int) AT91C_PA10_TWD     ), // Peripheral A
peter
parents:
diff changeset
  3919
		0); // Peripheral B
peter
parents:
diff changeset
  3920
}
peter
parents:
diff changeset
  3921
peter
parents:
diff changeset
  3922
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3923
//* \fn    AT91F_ADC_CfgPMC
peter
parents:
diff changeset
  3924
//* \brief Enable Peripheral clock in PMC for  ADC
peter
parents:
diff changeset
  3925
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3926
__inline void AT91F_ADC_CfgPMC (void)
peter
parents:
diff changeset
  3927
{
peter
parents:
diff changeset
  3928
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  3929
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  3930
		((unsigned int) 1 << AT91C_ID_ADC));
peter
parents:
diff changeset
  3931
}
peter
parents:
diff changeset
  3932
peter
parents:
diff changeset
  3933
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3934
//* \fn    AT91F_ADC_CfgPIO
peter
parents:
diff changeset
  3935
//* \brief Configure PIO controllers to drive ADC signals
peter
parents:
diff changeset
  3936
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3937
__inline void AT91F_ADC_CfgPIO (void)
peter
parents:
diff changeset
  3938
{
peter
parents:
diff changeset
  3939
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3940
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3941
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3942
		0, // Peripheral A
peter
parents:
diff changeset
  3943
		((unsigned int) AT91C_PB18_ADTRG   )); // Peripheral B
peter
parents:
diff changeset
  3944
}
peter
parents:
diff changeset
  3945
peter
parents:
diff changeset
  3946
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3947
//* \fn    AT91F_PWMC_CH3_CfgPIO
peter
parents:
diff changeset
  3948
//* \brief Configure PIO controllers to drive PWMC_CH3 signals
peter
parents:
diff changeset
  3949
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3950
__inline void AT91F_PWMC_CH3_CfgPIO (void)
peter
parents:
diff changeset
  3951
{
peter
parents:
diff changeset
  3952
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3953
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3954
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3955
		((unsigned int) AT91C_PB22_PWM3    ), // Peripheral A
peter
parents:
diff changeset
  3956
		((unsigned int) AT91C_PB30_PWM3    )); // Peripheral B
peter
parents:
diff changeset
  3957
}
peter
parents:
diff changeset
  3958
peter
parents:
diff changeset
  3959
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3960
//* \fn    AT91F_PWMC_CH2_CfgPIO
peter
parents:
diff changeset
  3961
//* \brief Configure PIO controllers to drive PWMC_CH2 signals
peter
parents:
diff changeset
  3962
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3963
__inline void AT91F_PWMC_CH2_CfgPIO (void)
peter
parents:
diff changeset
  3964
{
peter
parents:
diff changeset
  3965
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3966
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3967
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3968
		((unsigned int) AT91C_PB21_PWM2    ), // Peripheral A
peter
parents:
diff changeset
  3969
		((unsigned int) AT91C_PB29_PWM2    )); // Peripheral B
peter
parents:
diff changeset
  3970
}
peter
parents:
diff changeset
  3971
peter
parents:
diff changeset
  3972
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3973
//* \fn    AT91F_PWMC_CH1_CfgPIO
peter
parents:
diff changeset
  3974
//* \brief Configure PIO controllers to drive PWMC_CH1 signals
peter
parents:
diff changeset
  3975
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3976
__inline void AT91F_PWMC_CH1_CfgPIO (void)
peter
parents:
diff changeset
  3977
{
peter
parents:
diff changeset
  3978
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3979
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3980
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3981
		((unsigned int) AT91C_PB20_PWM1    ), // Peripheral A
peter
parents:
diff changeset
  3982
		((unsigned int) AT91C_PB28_PWM1    )); // Peripheral B
peter
parents:
diff changeset
  3983
}
peter
parents:
diff changeset
  3984
peter
parents:
diff changeset
  3985
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3986
//* \fn    AT91F_PWMC_CH0_CfgPIO
peter
parents:
diff changeset
  3987
//* \brief Configure PIO controllers to drive PWMC_CH0 signals
peter
parents:
diff changeset
  3988
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3989
__inline void AT91F_PWMC_CH0_CfgPIO (void)
peter
parents:
diff changeset
  3990
{
peter
parents:
diff changeset
  3991
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  3992
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  3993
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  3994
		((unsigned int) AT91C_PB19_PWM0    ), // Peripheral A
peter
parents:
diff changeset
  3995
		((unsigned int) AT91C_PB27_PWM0    )); // Peripheral B
peter
parents:
diff changeset
  3996
}
peter
parents:
diff changeset
  3997
peter
parents:
diff changeset
  3998
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  3999
//* \fn    AT91F_RTTC_CfgPMC
peter
parents:
diff changeset
  4000
//* \brief Enable Peripheral clock in PMC for  RTTC
peter
parents:
diff changeset
  4001
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4002
__inline void AT91F_RTTC_CfgPMC (void)
peter
parents:
diff changeset
  4003
{
peter
parents:
diff changeset
  4004
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4005
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4006
		((unsigned int) 1 << AT91C_ID_SYS));
peter
parents:
diff changeset
  4007
}
peter
parents:
diff changeset
  4008
peter
parents:
diff changeset
  4009
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4010
//* \fn    AT91F_UDP_CfgPMC
peter
parents:
diff changeset
  4011
//* \brief Enable Peripheral clock in PMC for  UDP
peter
parents:
diff changeset
  4012
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4013
__inline void AT91F_UDP_CfgPMC (void)
peter
parents:
diff changeset
  4014
{
peter
parents:
diff changeset
  4015
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4016
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4017
		((unsigned int) 1 << AT91C_ID_UDP));
peter
parents:
diff changeset
  4018
}
peter
parents:
diff changeset
  4019
peter
parents:
diff changeset
  4020
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4021
//* \fn    AT91F_EMAC_CfgPMC
peter
parents:
diff changeset
  4022
//* \brief Enable Peripheral clock in PMC for  EMAC
peter
parents:
diff changeset
  4023
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4024
__inline void AT91F_EMAC_CfgPMC (void)
peter
parents:
diff changeset
  4025
{
peter
parents:
diff changeset
  4026
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4027
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4028
		((unsigned int) 1 << AT91C_ID_EMAC));
peter
parents:
diff changeset
  4029
}
peter
parents:
diff changeset
  4030
peter
parents:
diff changeset
  4031
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4032
//* \fn    AT91F_EMAC_CfgPIO
peter
parents:
diff changeset
  4033
//* \brief Configure PIO controllers to drive EMAC signals
peter
parents:
diff changeset
  4034
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4035
__inline void AT91F_EMAC_CfgPIO (void)
peter
parents:
diff changeset
  4036
{
peter
parents:
diff changeset
  4037
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  4038
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  4039
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  4040
		((unsigned int) AT91C_PB2_ETX0    ) |
peter
parents:
diff changeset
  4041
		((unsigned int) AT91C_PB12_ETXER   ) |
peter
parents:
diff changeset
  4042
		((unsigned int) AT91C_PB16_ECOL    ) |
peter
parents:
diff changeset
  4043
		((unsigned int) AT91C_PB15_ERXDV_ECRSDV) |
peter
parents:
diff changeset
  4044
		((unsigned int) AT91C_PB11_ETX3    ) |
peter
parents:
diff changeset
  4045
		((unsigned int) AT91C_PB6_ERX1    ) |
peter
parents:
diff changeset
  4046
		((unsigned int) AT91C_PB13_ERX2    ) |
peter
parents:
diff changeset
  4047
		((unsigned int) AT91C_PB3_ETX1    ) |
peter
parents:
diff changeset
  4048
		((unsigned int) AT91C_PB4_ECRS    ) |
peter
parents:
diff changeset
  4049
		((unsigned int) AT91C_PB8_EMDC    ) |
peter
parents:
diff changeset
  4050
		((unsigned int) AT91C_PB5_ERX0    ) |
peter
parents:
diff changeset
  4051
		((unsigned int) AT91C_PB18_EF100   ) |
peter
parents:
diff changeset
  4052
		((unsigned int) AT91C_PB14_ERX3    ) |
peter
parents:
diff changeset
  4053
		((unsigned int) AT91C_PB1_ETXEN   ) |
peter
parents:
diff changeset
  4054
		((unsigned int) AT91C_PB10_ETX2    ) |
peter
parents:
diff changeset
  4055
		((unsigned int) AT91C_PB0_ETXCK_EREFCK) |
peter
parents:
diff changeset
  4056
		((unsigned int) AT91C_PB9_EMDIO   ) |
peter
parents:
diff changeset
  4057
		((unsigned int) AT91C_PB7_ERXER   ) |
peter
parents:
diff changeset
  4058
		((unsigned int) AT91C_PB17_ERXCK   ), // Peripheral A
peter
parents:
diff changeset
  4059
		0); // Peripheral B
peter
parents:
diff changeset
  4060
}
peter
parents:
diff changeset
  4061
peter
parents:
diff changeset
  4062
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4063
//* \fn    AT91F_TC0_CfgPMC
peter
parents:
diff changeset
  4064
//* \brief Enable Peripheral clock in PMC for  TC0
peter
parents:
diff changeset
  4065
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4066
__inline void AT91F_TC0_CfgPMC (void)
peter
parents:
diff changeset
  4067
{
peter
parents:
diff changeset
  4068
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4069
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4070
		((unsigned int) 1 << AT91C_ID_TC0));
peter
parents:
diff changeset
  4071
}
peter
parents:
diff changeset
  4072
peter
parents:
diff changeset
  4073
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4074
//* \fn    AT91F_TC0_CfgPIO
peter
parents:
diff changeset
  4075
//* \brief Configure PIO controllers to drive TC0 signals
peter
parents:
diff changeset
  4076
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4077
__inline void AT91F_TC0_CfgPIO (void)
peter
parents:
diff changeset
  4078
{
peter
parents:
diff changeset
  4079
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  4080
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  4081
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  4082
		((unsigned int) AT91C_PB23_TIOA0   ) |
peter
parents:
diff changeset
  4083
		((unsigned int) AT91C_PB24_TIOB0   ), // Peripheral A
peter
parents:
diff changeset
  4084
		((unsigned int) AT91C_PB12_TCLK0   )); // Peripheral B
peter
parents:
diff changeset
  4085
}
peter
parents:
diff changeset
  4086
peter
parents:
diff changeset
  4087
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4088
//* \fn    AT91F_TC1_CfgPMC
peter
parents:
diff changeset
  4089
//* \brief Enable Peripheral clock in PMC for  TC1
peter
parents:
diff changeset
  4090
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4091
__inline void AT91F_TC1_CfgPMC (void)
peter
parents:
diff changeset
  4092
{
peter
parents:
diff changeset
  4093
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4094
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4095
		((unsigned int) 1 << AT91C_ID_TC1));
peter
parents:
diff changeset
  4096
}
peter
parents:
diff changeset
  4097
peter
parents:
diff changeset
  4098
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4099
//* \fn    AT91F_TC1_CfgPIO
peter
parents:
diff changeset
  4100
//* \brief Configure PIO controllers to drive TC1 signals
peter
parents:
diff changeset
  4101
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4102
__inline void AT91F_TC1_CfgPIO (void)
peter
parents:
diff changeset
  4103
{
peter
parents:
diff changeset
  4104
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  4105
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  4106
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  4107
		((unsigned int) AT91C_PB25_TIOA1   ) |
peter
parents:
diff changeset
  4108
		((unsigned int) AT91C_PB26_TIOB1   ), // Peripheral A
peter
parents:
diff changeset
  4109
		((unsigned int) AT91C_PB19_TCLK1   )); // Peripheral B
peter
parents:
diff changeset
  4110
}
peter
parents:
diff changeset
  4111
peter
parents:
diff changeset
  4112
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4113
//* \fn    AT91F_TC2_CfgPMC
peter
parents:
diff changeset
  4114
//* \brief Enable Peripheral clock in PMC for  TC2
peter
parents:
diff changeset
  4115
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4116
__inline void AT91F_TC2_CfgPMC (void)
peter
parents:
diff changeset
  4117
{
peter
parents:
diff changeset
  4118
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4119
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4120
		((unsigned int) 1 << AT91C_ID_TC2));
peter
parents:
diff changeset
  4121
}
peter
parents:
diff changeset
  4122
peter
parents:
diff changeset
  4123
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4124
//* \fn    AT91F_TC2_CfgPIO
peter
parents:
diff changeset
  4125
//* \brief Configure PIO controllers to drive TC2 signals
peter
parents:
diff changeset
  4126
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4127
__inline void AT91F_TC2_CfgPIO (void)
peter
parents:
diff changeset
  4128
{
peter
parents:
diff changeset
  4129
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  4130
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  4131
		AT91C_BASE_PIOB, // PIO controller base address
peter
parents:
diff changeset
  4132
		((unsigned int) AT91C_PB28_TIOB2   ) |
peter
parents:
diff changeset
  4133
		((unsigned int) AT91C_PB27_TIOA2   ), // Peripheral A
peter
parents:
diff changeset
  4134
		0); // Peripheral B
peter
parents:
diff changeset
  4135
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  4136
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  4137
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  4138
		0, // Peripheral A
peter
parents:
diff changeset
  4139
		((unsigned int) AT91C_PA15_TCLK2   )); // Peripheral B
peter
parents:
diff changeset
  4140
}
peter
parents:
diff changeset
  4141
peter
parents:
diff changeset
  4142
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4143
//* \fn    AT91F_MC_CfgPMC
peter
parents:
diff changeset
  4144
//* \brief Enable Peripheral clock in PMC for  MC
peter
parents:
diff changeset
  4145
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4146
__inline void AT91F_MC_CfgPMC (void)
peter
parents:
diff changeset
  4147
{
peter
parents:
diff changeset
  4148
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4149
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4150
		((unsigned int) 1 << AT91C_ID_SYS));
peter
parents:
diff changeset
  4151
}
peter
parents:
diff changeset
  4152
peter
parents:
diff changeset
  4153
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4154
//* \fn    AT91F_PIOA_CfgPMC
peter
parents:
diff changeset
  4155
//* \brief Enable Peripheral clock in PMC for  PIOA
peter
parents:
diff changeset
  4156
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4157
__inline void AT91F_PIOA_CfgPMC (void)
peter
parents:
diff changeset
  4158
{
peter
parents:
diff changeset
  4159
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4160
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4161
		((unsigned int) 1 << AT91C_ID_PIOA));
peter
parents:
diff changeset
  4162
}
peter
parents:
diff changeset
  4163
peter
parents:
diff changeset
  4164
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4165
//* \fn    AT91F_PIOB_CfgPMC
peter
parents:
diff changeset
  4166
//* \brief Enable Peripheral clock in PMC for  PIOB
peter
parents:
diff changeset
  4167
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4168
__inline void AT91F_PIOB_CfgPMC (void)
peter
parents:
diff changeset
  4169
{
peter
parents:
diff changeset
  4170
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4171
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4172
		((unsigned int) 1 << AT91C_ID_PIOB));
peter
parents:
diff changeset
  4173
}
peter
parents:
diff changeset
  4174
peter
parents:
diff changeset
  4175
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4176
//* \fn    AT91F_CAN_CfgPMC
peter
parents:
diff changeset
  4177
//* \brief Enable Peripheral clock in PMC for  CAN
peter
parents:
diff changeset
  4178
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4179
__inline void AT91F_CAN_CfgPMC (void)
peter
parents:
diff changeset
  4180
{
peter
parents:
diff changeset
  4181
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4182
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4183
		((unsigned int) 1 << AT91C_ID_CAN));
peter
parents:
diff changeset
  4184
}
peter
parents:
diff changeset
  4185
peter
parents:
diff changeset
  4186
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4187
//* \fn    AT91F_CAN_CfgPIO
peter
parents:
diff changeset
  4188
//* \brief Configure PIO controllers to drive CAN signals
peter
parents:
diff changeset
  4189
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4190
__inline void AT91F_CAN_CfgPIO (void)
peter
parents:
diff changeset
  4191
{
peter
parents:
diff changeset
  4192
	// Configure PIO controllers to periph mode
peter
parents:
diff changeset
  4193
	AT91F_PIO_CfgPeriph(
peter
parents:
diff changeset
  4194
		AT91C_BASE_PIOA, // PIO controller base address
peter
parents:
diff changeset
  4195
		((unsigned int) AT91C_PA20_CANTX   ) |
peter
parents:
diff changeset
  4196
		((unsigned int) AT91C_PA19_CANRX   ), // Peripheral A
peter
parents:
diff changeset
  4197
		0); // Peripheral B
peter
parents:
diff changeset
  4198
}
peter
parents:
diff changeset
  4199
peter
parents:
diff changeset
  4200
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4201
//* \fn    AT91F_PWMC_CfgPMC
peter
parents:
diff changeset
  4202
//* \brief Enable Peripheral clock in PMC for  PWMC
peter
parents:
diff changeset
  4203
//*----------------------------------------------------------------------------
peter
parents:
diff changeset
  4204
__inline void AT91F_PWMC_CfgPMC (void)
peter
parents:
diff changeset
  4205
{
peter
parents:
diff changeset
  4206
	AT91F_PMC_EnablePeriphClock(
peter
parents:
diff changeset
  4207
		AT91C_BASE_PMC, // PIO controller base address
peter
parents:
diff changeset
  4208
		((unsigned int) 1 << AT91C_ID_PWMC));
peter
parents:
diff changeset
  4209
}
peter
parents:
diff changeset
  4210
peter
parents:
diff changeset
  4211
#endif // lib_AT91SAM7X256_H