This file defines a useful set of functions for the PDCA interface on AVR32 devices.
Definition in file pdca.h.
#include <avr32/io.h>
Go to the source code of this file.
Data Structures | |
struct | pdca_channel_options_t |
PDCA channel options. More... | |
Defines | |
#define | PDCA_TRANSFER_SIZE_BYTE AVR32_PDCA_BYTE |
Size of PDCA transfer: byte. | |
#define | PDCA_TRANSFER_SIZE_HALF_WORD AVR32_PDCA_HALF_WORD |
Size of PDCA transfer: half-word. | |
#define | PDCA_TRANSFER_SIZE_WORD AVR32_PDCA_WORD |
Size of PDCA transfer: word. | |
PDCA Driver Status Codes | |
#define | PDCA_INVALID_ARGUMENT -1 |
#define | PDCA_SUCCESS 0 |
PDCA Transfer Status Codes | |
#define | PDCA_TRANSFER_COMPLETE AVR32_PDCA_TRC_MASK |
#define | PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO AVR32_PDCA_RCZ_MASK |
#define | PDCA_TRANSFER_ERROR AVR32_PDCA_TERR_MASK |
Functions | |
void | pdca_disable (unsigned int pdca_ch_number) |
Disable the PDCA for the given channel. | |
void | pdca_disable_interrupt_reload_counter_zero (unsigned int pdca_ch_number) |
Disable PDCA transfer interrupt when TCRR reaches zero. | |
void | pdca_disable_interrupt_transfer_complete (unsigned int pdca_ch_number) |
Disable PDCA transfer interrupt when completed (ie TCR and TCRR are both zero). | |
void | pdca_disable_interrupt_transfer_error (unsigned int pdca_ch_number) |
Disable PDCA transfer error interrupt. | |
void | pdca_enable (unsigned int pdca_ch_number) |
Enable the PDCA for the given channel. | |
void | pdca_enable_interrupt_reload_counter_zero (unsigned int pdca_ch_number) |
Enable PDCA transfer interrupt when TCRR reaches zero. | |
void | pdca_enable_interrupt_transfer_complete (unsigned int pdca_ch_number) |
Enable PDCA transfer interrupt when completed (ie TCR and TCRR are both zero). | |
void | pdca_enable_interrupt_transfer_error (unsigned int pdca_ch_number) |
Enable PDCA transfer error interrupt. | |
unsigned int | pdca_get_channel_status (unsigned int pdca_ch_number) |
Get the PDCA channel transfer enable status. | |
volatile avr32_pdca_channel_t * | pdca_get_handler (unsigned int pdca_ch_number) |
Get PDCA channel handler. | |
unsigned int | pdca_get_load_size (unsigned int pdca_ch_number) |
Get PDCA channel load size (or remaining size if transfer started). | |
unsigned int | pdca_get_reload_size (unsigned int pdca_ch_number) |
Get PDCA channel reload size. | |
unsigned long | pdca_get_transfer_status (unsigned int pdca_ch_number) |
Get PDCA channel transfer status. | |
int | pdca_init_channel (unsigned int pdca_ch_number, const pdca_channel_options_t *opt) |
Set the channel configuration. | |
void | pdca_load_channel (unsigned int pdca_ch_number, volatile void *addr, unsigned int size) |
Set PDCA channel load values. | |
void | pdca_reload_channel (unsigned int pdca_ch_number, volatile void *addr, unsigned int size) |
Set PDCA channel reload values. | |
void | pdca_set_peripheral_select (unsigned int pdca_ch_number, unsigned int pid) |
Set the peripheral function to use with the PDCA channel. | |
void | pdca_set_transfer_size (unsigned int pdca_ch_number, unsigned int transfer_size) |
Set the size of the transfer. |
#define PDCA_INVALID_ARGUMENT -1 |
#define PDCA_SUCCESS 0 |
#define PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO AVR32_PDCA_RCZ_MASK |
#define PDCA_TRANSFER_SIZE_BYTE AVR32_PDCA_BYTE |
#define PDCA_TRANSFER_SIZE_HALF_WORD AVR32_PDCA_HALF_WORD |
#define PDCA_TRANSFER_SIZE_WORD AVR32_PDCA_WORD |
void pdca_disable | ( | unsigned int | pdca_ch_number | ) |
Disable the PDCA for the given channel.
pdca_ch_number | PDCA channel |
Definition at line 103 of file pdca.c.
References pdca_get_handler().
00104 { 00105 // get the correct channel pointer 00106 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00107 00108 // Disable transfer 00109 pdca_channel->cr = AVR32_PDCA_TDIS_MASK; 00110 00111 }
void pdca_disable_interrupt_reload_counter_zero | ( | unsigned int | pdca_ch_number | ) |
Disable PDCA transfer interrupt when TCRR reaches zero.
pdca_ch_number | PDCA channel |
Definition at line 265 of file pdca.c.
References pdca_get_handler().
Referenced by pdca_init_channel().
00266 { 00267 // get the correct channel pointer 00268 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00269 00270 Bool global_interrupt_enabled = Is_global_interrupt_enabled(); 00271 00272 if (global_interrupt_enabled) Disable_global_interrupt(); 00273 pdca_channel->idr = AVR32_PDCA_RCZ_MASK; 00274 pdca_channel->isr; 00275 if (global_interrupt_enabled) Enable_global_interrupt(); 00276 }
void pdca_disable_interrupt_transfer_complete | ( | unsigned int | pdca_ch_number | ) |
Disable PDCA transfer interrupt when completed (ie TCR and TCRR are both zero).
pdca_ch_number | PDCA channel |
Definition at line 242 of file pdca.c.
References pdca_get_handler().
Referenced by pdca_init_channel().
00243 { 00244 // get the correct channel pointer 00245 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00246 00247 Bool global_interrupt_enabled = Is_global_interrupt_enabled(); 00248 00249 if (global_interrupt_enabled) Disable_global_interrupt(); 00250 pdca_channel->idr = AVR32_PDCA_TRC_MASK; 00251 pdca_channel->isr; 00252 if (global_interrupt_enabled) Enable_global_interrupt(); 00253 }
void pdca_disable_interrupt_transfer_error | ( | unsigned int | pdca_ch_number | ) |
Disable PDCA transfer error interrupt.
pdca_ch_number | PDCA channel |
Definition at line 219 of file pdca.c.
References pdca_get_handler().
00220 { 00221 // get the correct channel pointer 00222 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00223 00224 Bool global_interrupt_enabled = Is_global_interrupt_enabled(); 00225 00226 if (global_interrupt_enabled) Disable_global_interrupt(); 00227 pdca_channel->idr = AVR32_PDCA_TERR_MASK; 00228 pdca_channel->isr; 00229 if (global_interrupt_enabled) Enable_global_interrupt(); 00230 }
void pdca_enable | ( | unsigned int | pdca_ch_number | ) |
Enable the PDCA for the given channel.
pdca_ch_number | PDCA channel |
Definition at line 114 of file pdca.c.
References pdca_get_handler().
Referenced by main().
00115 { 00116 // get the correct channel pointer 00117 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00118 00119 // Enable transfer 00120 pdca_channel->cr = AVR32_PDCA_TEN_MASK; 00121 }
void pdca_enable_interrupt_reload_counter_zero | ( | unsigned int | pdca_ch_number | ) |
Enable PDCA transfer interrupt when TCRR reaches zero.
pdca_ch_number | PDCA channel |
Definition at line 279 of file pdca.c.
References pdca_get_handler().
Referenced by main().
00280 { 00281 // get the correct channel pointer 00282 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00283 00284 pdca_channel->ier = AVR32_PDCA_RCZ_MASK; 00285 }
void pdca_enable_interrupt_transfer_complete | ( | unsigned int | pdca_ch_number | ) |
Enable PDCA transfer interrupt when completed (ie TCR and TCRR are both zero).
pdca_ch_number | PDCA channel |
Definition at line 256 of file pdca.c.
References pdca_get_handler().
00257 { 00258 // get the correct channel pointer 00259 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00260 00261 pdca_channel->ier = AVR32_PDCA_TRC_MASK; 00262 }
void pdca_enable_interrupt_transfer_error | ( | unsigned int | pdca_ch_number | ) |
Enable PDCA transfer error interrupt.
pdca_ch_number | PDCA channel |
Definition at line 233 of file pdca.c.
References pdca_get_handler().
00234 { 00235 // get the correct channel pointer 00236 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00237 00238 pdca_channel->ier = AVR32_PDCA_TERR_MASK; 00239 }
unsigned int pdca_get_channel_status | ( | unsigned int | pdca_ch_number | ) |
Get the PDCA channel transfer enable status.
pdca_ch_number | PDCA channel |
1
if channel transfer is enabled, else 0
Definition at line 94 of file pdca.c.
References pdca_get_handler().
00095 { 00096 // get the correct channel pointer 00097 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00098 00099 return (pdca_channel->sr & AVR32_PDCA_TEN_MASK) != 0; 00100 }
volatile avr32_pdca_channel_t* pdca_get_handler | ( | unsigned int | pdca_ch_number | ) |
Get PDCA channel handler.
pdca_ch_number | PDCA channel |
Definition at line 53 of file pdca.c.
References PDCA_INVALID_ARGUMENT.
Referenced by pdca_disable(), pdca_disable_interrupt_reload_counter_zero(), pdca_disable_interrupt_transfer_complete(), pdca_disable_interrupt_transfer_error(), pdca_enable(), pdca_enable_interrupt_reload_counter_zero(), pdca_enable_interrupt_transfer_complete(), pdca_enable_interrupt_transfer_error(), pdca_get_channel_status(), pdca_get_load_size(), pdca_get_reload_size(), pdca_get_transfer_status(), pdca_init_channel(), pdca_load_channel(), pdca_reload_channel(), pdca_set_peripheral_select(), and pdca_set_transfer_size().
00054 { 00055 // get the correct channel pointer 00056 volatile avr32_pdca_channel_t *pdca_channel = &AVR32_PDCA.channel[pdca_ch_number]; 00057 00058 if (pdca_ch_number >= AVR32_PDCA_CHANNEL_LENGTH) 00059 return (volatile avr32_pdca_channel_t *)PDCA_INVALID_ARGUMENT; 00060 00061 return pdca_channel; 00062 }
unsigned int pdca_get_load_size | ( | unsigned int | pdca_ch_number | ) |
Get PDCA channel load size (or remaining size if transfer started).
pdca_ch_number | PDCA channel |
Definition at line 124 of file pdca.c.
References pdca_get_handler().
00125 { 00126 // get the correct channel pointer 00127 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00128 00129 return pdca_channel->tcr; 00130 }
unsigned int pdca_get_reload_size | ( | unsigned int | pdca_ch_number | ) |
Get PDCA channel reload size.
pdca_ch_number | PDCA channel |
Definition at line 149 of file pdca.c.
References pdca_get_handler().
00150 { 00151 // get the correct channel pointer 00152 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00153 00154 return pdca_channel->tcrr; 00155 }
unsigned long pdca_get_transfer_status | ( | unsigned int | pdca_ch_number | ) |
Get PDCA channel transfer status.
pdca_ch_number | PDCA channel |
PDCA_TRANSFER_ERROR
;PDCA_TRANSFER_COMPLETE
;PDCA_TRANSFER_COUNTER_RELOAD_IS_ZERO
. Definition at line 288 of file pdca.c.
References pdca_get_handler().
00289 { 00290 // get the correct channel pointer 00291 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00292 00293 return pdca_channel->isr; 00294 }
int pdca_init_channel | ( | unsigned int | pdca_ch_number, | |
const pdca_channel_options_t * | opt | |||
) |
Set the channel configuration.
pdca_ch_number | PDCA channel | |
opt | channel option |
Definition at line 65 of file pdca.c.
References pdca_channel_options_t::addr, pdca_disable_interrupt_reload_counter_zero(), pdca_disable_interrupt_transfer_complete(), pdca_get_handler(), PDCA_SUCCESS, pdca_channel_options_t::pid, pdca_channel_options_t::r_addr, pdca_channel_options_t::r_size, pdca_channel_options_t::size, and pdca_channel_options_t::transfer_size.
Referenced by main().
00066 { 00067 // get the correct channel pointer 00068 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00069 00070 pdca_disable_interrupt_transfer_complete(pdca_ch_number); // disable channel interrupt 00071 pdca_disable_interrupt_reload_counter_zero(pdca_ch_number); // disable channel interrupt 00072 00073 Bool global_interrupt_enabled = Is_global_interrupt_enabled(); 00074 00075 if (global_interrupt_enabled) Disable_global_interrupt(); 00076 pdca_channel->mar = (unsigned long)opt->addr; 00077 pdca_channel->tcr = opt->size; 00078 pdca_channel->psr = opt->pid; 00079 pdca_channel->marr = (unsigned long)opt->r_addr; 00080 pdca_channel->tcrr = opt->r_size; 00081 pdca_channel->mr = 00082 #if (defined AVR32_PDCA_120_H_INCLUDED ) || (defined AVR32_PDCA_121_H_INCLUDED ) || (defined AVR32_PDCA_122_H_INCLUDED ) 00083 opt->etrig << AVR32_PDCA_ETRIG_OFFSET | 00084 #endif // #ifdef AVR32_PDCA_120_H_INCLUDED 00085 opt->transfer_size << AVR32_PDCA_SIZE_OFFSET; 00086 pdca_channel->cr = AVR32_PDCA_ECLR_MASK; 00087 pdca_channel->isr; 00088 if (global_interrupt_enabled) Enable_global_interrupt(); 00089 00090 return PDCA_SUCCESS; 00091 }
void pdca_load_channel | ( | unsigned int | pdca_ch_number, | |
volatile void * | addr, | |||
unsigned int | size | |||
) |
Set PDCA channel load values.
pdca_ch_number | PDCA channel | |
addr | address where data to load are stored | |
size | size of the data block to load |
Definition at line 133 of file pdca.c.
References pdca_get_handler().
00134 { 00135 // get the correct channel pointer 00136 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00137 00138 Bool global_interrupt_enabled = Is_global_interrupt_enabled(); 00139 00140 if (global_interrupt_enabled) Disable_global_interrupt(); 00141 pdca_channel->mar = (unsigned long)addr; 00142 pdca_channel->tcr = size; 00143 pdca_channel->cr = AVR32_PDCA_ECLR_MASK; 00144 pdca_channel->isr; 00145 if (global_interrupt_enabled) Enable_global_interrupt(); 00146 }
void pdca_reload_channel | ( | unsigned int | pdca_ch_number, | |
volatile void * | addr, | |||
unsigned int | size | |||
) |
Set PDCA channel reload values.
pdca_ch_number | PDCA channel | |
addr | address where data to load are stored | |
size | size of the data block to load |
Definition at line 158 of file pdca.c.
References pdca_get_handler().
Referenced by pdca_int_handler().
00159 { 00160 // get the correct channel pointer 00161 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00162 00163 Bool global_interrupt_enabled = Is_global_interrupt_enabled(); 00164 00165 if (global_interrupt_enabled) Disable_global_interrupt(); 00166 // set up next memory address 00167 pdca_channel->marr = (unsigned long)addr; 00168 // set up next memory size 00169 pdca_channel->tcrr = size; 00170 pdca_channel->cr = AVR32_PDCA_ECLR_MASK; 00171 pdca_channel->isr; 00172 if (global_interrupt_enabled) Enable_global_interrupt(); 00173 }
void pdca_set_peripheral_select | ( | unsigned int | pdca_ch_number, | |
unsigned int | pid | |||
) |
Set the peripheral function to use with the PDCA channel.
pdca_ch_number | PDCA channel | |
pid | the peripheral ID |
Definition at line 176 of file pdca.c.
References pdca_get_handler().
00177 { 00178 // get the correct channel pointer 00179 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00180 00181 pdca_channel->psr = pid; 00182 }
void pdca_set_transfer_size | ( | unsigned int | pdca_ch_number, | |
unsigned int | transfer_size | |||
) |
Set the size of the transfer.
pdca_ch_number | PDCA channel | |
transfer_size | size of the transfer (byte, half-word or word) |
Definition at line 185 of file pdca.c.
References pdca_get_handler().
00186 { 00187 // get the correct channel pointer 00188 volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number); 00189 00190 pdca_channel->mr = (pdca_channel->mr & ~AVR32_PDCA_SIZE_MASK) | 00191 transfer_size << AVR32_PDCA_SIZE_OFFSET; 00192 }