Title: User API
1TIM MicroController
TIM CUSTOM API (CONFIGURATION)
ifndef genconfig_h define genconfig_h
define CAN_EN 1 //Enable/Disable CAN (1
or 0) define CAN_BAUD //125k 250k 500k
1M define UART0_EN 1
//Enable/Disable UART0 (1 or 0) --will be set
to Mode 3 by default define BAUDRATE0 9600
// Baud rate of UART in bps. Can
be set to 1200,9600,57600,115200. define
UART1_EN 1 //Enable/Disable UART0 (1 or 0)
--will be set to Mode 3 by default define
BAUDRATE1 9600 // Baud rate
of UART in bps. Can be set to
1200,9600,57600,115200. define SPI_MODE
MM //Master - multi-master, 3-wire single-master,
4-wire single-master, //Slave - 4-wire,
3-wire //(Master - MM, M3, M4, Slave - S4,
S3) define I2C_MODE M //Master or
Slave define PCA_IN 3 //Defines number of
PCA inputs (0 to 6) define PCA_OUT
1 //Defines number of PCA outputs (0 to
6) define PCA_TSRC SYS12 //Defines the timer
source of the PCA (SYSCLK/12 gtSYS12,
//SYSCLK/4 gtSYS4, Timer0 gtTIMER0, //SYSCL
K gt SYSC) ?-- ECI, External Clock/8 define
GPIO_IN 2 //Defines number of GPIO inputs
(0 to 9 - PCA) define GPO_OUT 2 //Defines
number of GPIO outputs (0 to 9 -(PCA
GPIO_IN)) define GPO_PSHPUL
1 //Defines number of pushpull outputs(0 to 9),
the first n are pushpull define Timer0_EN
0 //Disabled gt0,13-bitgt1, 16-bitgt2, 8-bit
auto reloadgt3, Two 8- //bitgt4 define
Timer1_EN 0 //Disabled gt0,13-bitgt1,
16-bitgt2, 8-bit auto reloadgt3 define Timer2_EN
0 //Disabled gt0,16-bit auto reloadgt1,
16-bit capturegt2, Toggle //Outputgt3 define
Timer3_EN 0 //Disabled gt0,16-bit auto
reloadgt1, 16-bit capturegt2, Toggle
//Outputgt3 define Timer4_EN
0 //Disabled gt0,16-bit auto reloadgt1, 16-bit
capturegt2, Toggle //Outputgt3 define
SYSCLK 24500000 // Internal
oscillator frequency in Hz (can be either
24500000 or //2500000) // Other options
?-- 22.1184M, 18.432M, 11.0592M, 3.6864M define
SAMPLE_RATE 50000 // Sample
frequency in Hz define INT_DEC 256
// integrate and decimate ratio
C8051F040/1/2/3/4/5/6/7 Analog
Peripherals High-Speed 8051 µC Core -Pipelined
instruction architecture executes 70 of
instruction set in 1 or 2 system clocks -Up to
25 MIPS throughput with 25 MHz clock Memory -4352
bytes internal data RAM (4 k 256) -64 kB
(C8051F041) Flash Digital Peripherals -Bosch
Controller Area Network (CAN 2.0B), hardware
SMBus (I2C Compatible), SPI, and two UART
Programmable 16-bit counter/timer array with
6 capture/compare modules -5 general purpose
16-bit counter/timers Clock Sources -Internal
calibrated programmable oscillator 3 to
24.5 MHz -Real-time clock mode using Timer 2, 3,
4, or PCA Supply Voltage 2.7 to 3.6 V
Controller Area Network (CAN)
- Is a high-integrity serial data communications
bus for real-time applications - Operates at data rates of up to 1 Megabits per
second - Has excellent error detection and confinement
capabilities - Was originally developed by Bosch for use in cars
- Is now being used in many other industrial
automation and control applications
TIM Communication Library / Firmware
Driver API This API is the method of
communication between the IDEAnix message router
and the CAN driver. UINT8 init_can ( void )
Sets up the hardware prior to any other API
calls. i.e. initializes one channel to
receive all and one to send all in
"implementation one or four channels for
sending and 28 for receiving in
"implementation two. UINT8 send_pkt (
CAN_ID_TYPE can_id , PAYLOAD_TYPE
payload ) Pumps a CAN frame contaning the
ID and 4-byte payload out on the bus.
BLOCKING call. UINT8 reg_pkt ( CAN_ID_TYPE
can_id ) Tells the driver layer to capture
CAN messages with the passed ID. UINT8
unreg_pkt ( CAN_ID_TYPE can_id )
De-allocates space (or hardware capture channel)
previously allocated by reg_pkt(). UINT8
get_pkt ( CAN_ID_TYPE can_id_ptr,
PAYLOAD_TYPE payload_ptr ) Places the first
can_id and payload in the pipe/queue/buffer
into the memory space referred to by the
pointers.
User API This is the API used between user code
and the IDEAnix message router. UINT8 send_msg (
CAN_ID_TYPE can_id , PAYLOAD_TYPE
payload ) Passes a CAN message and it's ID
to the router layer to be stuffed into the
D' input queue. UINT8 reg_msg ( CAN_ID_TYPE
can_id ) Tells the IDEAnix router layer to
grab incoming messages with can_id off
the bus and to place them into the tasks incoming
queue. UINT8 unreg_msg ( CAN_ID_TYPE can_id )
De-allocates space in hardware for this
can_id and stops messages of this type
from being placed into the tasks' incoming
buffer. UINT8 get_msg ( CAN_ID_TYPE
can_id_ptr, PAYLOAD_TYPE
payload_ptr ) Places the first can_id
and payload in the pipe/queue/buffer into the
memory space refered to by the
pointers. UINT8 check_msg ( void )
Returns 1 if there is any data waiting in the
pipe/queue/buffer. Returns 0 if there is
no data waiting in the pipe/queue/buffer.