TNeo  v1.07
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros
tn_arch_pic24_bfa.h File Reference

Detailed Description

Atomic bit-field access macros for PIC24/dsPIC.

Initially, the code was taken from the article by Alex Borisov (russian), and modified a bit.

The kernel would not probably provide that kind of functionality, but the kernel itself needs it, so, it is made public so that application can use it too.

Definition in file tn_arch_pic24_bfa.h.

Go to the source code of this file.

Macros

#define TN_BFA_SET   0x1111
 Command for TN_BFA() macro: Set bits in the bit field by mask; ... macro param should be set to the bit mask to set. More...
 
#define TN_BFA_CLR   0x2222
 Command for TN_BFA() macro: Clear bits in the bit field by mask; ... macro param should be set to the bit mask to clear. More...
 
#define TN_BFA_INV   0x3333
 Command for TN_BFA() macro: Invert bits in the bit field by mask; ... macro param should be set to the bit mask to invert. More...
 
#define TN_BFA_WR   0xAAAA
 Command for TN_BFA() macro: Write bit field; ... macro param should be set to the value to write. More...
 
#define TN_BFA_RD   0xBBBB
 Command for TN_BFA() macro: Read bit field; ... macro param ignored. More...
 
#define TN_BFA(comm, reg_name, field_name,...)
 Macro for atomic access to the structure bit field. More...
 
#define TN_BFAR(comm, reg_name, lower, upper,...)
 Macro for atomic access to the structure bit field specified as a range. More...
 

Macro Definition Documentation

#define TN_BFA_SET   0x1111

Command for TN_BFA() macro: Set bits in the bit field by mask; ... macro param should be set to the bit mask to set.

Definition at line 76 of file tn_arch_pic24_bfa.h.

#define TN_BFA_CLR   0x2222

Command for TN_BFA() macro: Clear bits in the bit field by mask; ... macro param should be set to the bit mask to clear.

Definition at line 80 of file tn_arch_pic24_bfa.h.

#define TN_BFA_INV   0x3333

Command for TN_BFA() macro: Invert bits in the bit field by mask; ... macro param should be set to the bit mask to invert.

Definition at line 84 of file tn_arch_pic24_bfa.h.

#define TN_BFA_WR   0xAAAA

Command for TN_BFA() macro: Write bit field; ... macro param should be set to the value to write.

Definition at line 88 of file tn_arch_pic24_bfa.h.

#define TN_BFA_RD   0xBBBB

Command for TN_BFA() macro: Read bit field; ... macro param ignored.

Definition at line 92 of file tn_arch_pic24_bfa.h.

#define TN_BFA (   comm,
  reg_name,
  field_name,
  ... 
)

Macro for atomic access to the structure bit field.

The BFA acronym means Bit Field Access.

Parameters
commcommand to execute:
reg_nameregister name (PORTA, CMCON, ...).
field_namestructure field name
...used if only comm != TN_BFA_RD. Meaning depends on the comm, see comments for specific command: TN_BFA_WR, etc.

Usage examples:

int a = 0x02;
//-- Set third bit of the INT0IP field in the IPC0 register:
// IPC0bits.INT0IP |= (1 << 2);
TN_BFA(TN_BFA_SET, IPC0, INT0IP, (1 << 2));
//-- Clear second bit of the INT0IP field in the IPC0 register:
// IPC0bits.INT0IP &= ~(1 << 1);
TN_BFA(TN_BFA_CLR, IPC0, INT0IP, (1 << 1));
//-- Invert two less-significant bits of the INT0IP field
// in the IPC0 register:
// IPC0bits.INT0IP ^= 0x03;
TN_BFA(TN_BFA_INV, IPC0, INT0IP, 0x03);
//-- Write value 0x05 to the INT0IP field of the IPC0 register:
// IPC0bits.INT0IP = 0x05;
TN_BFA(TN_BFA_WR, IPC0, INT0IP, 0x05);
//-- Write value of the variable a to the INT0IP field of the IPC0
// register:
// IPC0bits.INT0IP = a;
TN_BFA(TN_BFA_WR, IPC0, INT0IP, a);
//-- Read the value that is stored in the INT0IP field of the IPC0
// register, to the int variable a:
// int a = IPC0bits.INT0IP;
a = TN_BFA(TN_BFA_RD, IPC0, INT0IP);

Definition at line 154 of file tn_arch_pic24_bfa.h.

#define TN_BFAR (   comm,
  reg_name,
  lower,
  upper,
  ... 
)

Macro for atomic access to the structure bit field specified as a range.

Parameters
commcommand to execute:
reg_namevariable name (PORTA, CMCON, ...). Variable should be in the near memory (first 8 KB)
lowernumber of lowest affected bit of the field
uppernumber of highest affected bit of the field
...used if only comm != TN_BFA_RD. Meaning depends on the comm, see comments for specific command: TN_BFA_WR, etc.

Usage examples:

int a = 0x02;
//-- Write constant 0xaa to the least significant byte of the TRISB
// register:
TN_BFAR(TN_BFA_WR, TRISB, 0, 7, 0xaa);
//-- Invert least significant nibble of the most significant byte
// in the register TRISB:
TN_BFAR(TN_BFA_INV, TRISB, 8, 15, 0x0f);
//-- Get 5 least significant bits from the register TRISB and store
// result to the variable a
a = TN_BFAR(TN_BFA_RD, TRISB, 0, 4);

Definition at line 270 of file tn_arch_pic24_bfa.h.