EC microcontroller - CR16C+

EC microcontroller


Due to increased demand, the KBC/EC chip, besides being the SMBUS master, has added many new functions, requiring the integration of other modules to fulfill these needs. Taking KBC as an example, a module is needed to decode PORT60/64 and then transmit instructions and data to the chip's core processor, along with firmware to send data back to the system informing it that data reception is complete. This chapter will detail the functions of each module in the KBC/EC chip, starting with understanding their functions, then considering their applications, and finally demonstrating how to configure and start the firmware to accomplish the tasks required by each module.


  1. CR16X language


The microprocessors used by ECs are selected based on functional requirements. Currently, the 8-bit 8051, CR16C+, and ARM Cortex M0-M4F series are available. This article focuses on the CR16C+, which has less information available. Early EC firmware was written using a single-chip assembly language. Therefore, to become an EC programmer, one needs to understand the instructions of the single-chip assembly language to handle problems caused by program optimization. Furthermore, understanding the instruction set provides a better understanding of the microprocessor architecture.

  • Data Type

CR16X data types are divided into integers and Boolean numbers. Boolean numbers are converted to integers during assembly. Integers can be 8, 16, or 32 bits, etc.

  • Register

The CR16X's registers are divided into several parts: 16 general-purpose registers, 4 registers for addressing, an arithmetic processor status register, a setting register, and a group of registers for debugging.




R0-R13It is used for general data calculation or transfer, among whichR12andR13It is 32-bit and can be used for program addressing; it needs to be enclosed in parentheses when used. RA is used to store the return address when a subroutine is called. SP is used to indicate the firmware stack address index.

  • PC- This refers to the program address index of the firmware.

  • ISP(Interrupt Stack Pointer) is used to store stack pointers used by hardware interrupts.

  • USP(User Stack Pointer) is used to store stack pointers used by programmable interrupts.

  • INTBASE(Interrupt Base Register) A temporary register that stores interrupt service routines.

  • PSR(Processor Status Register) Processor status register, as shown in the figure below.


Flag

Description

T

Used for program step-by-step tracing

P

Used for program tracing

IN

It is used to indicate that a program is entering a user-programmable interrupt service routine. In other words, the USP is being used.

F

Used to indicate the result of an instruction, such as the result of a test instruction.

AND

Used to indicate whether a programmable interrupt can occur.

I

Used to indicate whether any interruption can occur.

C

Used to indicate whether a carry or borrow occurred after addition or subtraction.

L

Used to represent the result of a comparison between two unsigned integers, where the destination variable is less than the source variable.

WITH

Used to represent the result of a comparison between two integers, where the destination variable equals the source variable.

N

Used to represent the result of a comparison between two signed integers, where the destination variable is less than the source variable.


  • CFG (The Configuration Register is used to set data parameters.


Flag

Description

DC

Configure Data Cache functionality

LDC

Configure Lock Data Cache functionality

IC

Configure the Instruction Cache

LIC

Configure the Lock Instruction Cache

ED

The address index of the ISR is 16/32 bits.

SR

Indicates whether to be compatible with the old CR16B instructions.


  • Instruction set

The format of a CR16X instruction is instruction + source variable + destination variable. Instruction addressing modes can be divided into several types:

  • Register/Pair Mode – Both source and destination are registers. Example: ADDB R1, R2

  • Immediate Addressing [Immediate Mode] – Source variables are immediate values. EX: MULW $4,R4

  • Relative addressing (Relative Mode) – The value of the variable originates from the relative memory space and can only be obtained by referring to a general temporary register or the PC. EX: LOADW 12(R5), R6

  • Absolute addressing – The value of a variable is derived from an absolute memory space. Example: LOADB 40000, R5

  • Indexed addressing [Index Mode] - The value of the variable originates from the memory space relative to the index value, which is stored in R12 or R13. EX: LOADW [R12]4(R5,R4),R6


The CR16X commands include:

  • Moving instructions

    • MOVB/W/D – Move the source variable to the destination variable

    • MOVXB/W – Converts original BYTE/WORD data to WORD/DWORD based on the sign number.

    • MOVZB/W - Converts the original BYTE/WORD data to WORD/DWORD, padding all high-order bits with zeros.

  • Mathematical Calculation Instructions

    • ADDB/W/D – General Addition

    • ADDUB/W/D – General addition does not affect PSR.

    • ADDCB/W/D – Adds the carry flag to the destination variable.

    • SUBB/W/D – General subtraction.

    • SUBCB/W - Subtract the carry flag along with the target variable.

    • MULB/W – General multiplication.

    • MULSB/W – Multiplication of signed numbers.

    • MACSW/MACUW/MACQW – Multiply two signed/unsigned variables and add the result to the target variable.

  • Comparison instructions

    • CMPB/W/D – Comparison of two variables

    • Bcond – If the conditions are met, jump to a space within a relative spatial range of 0-16M.

    • BEQ0B/W, BNE0B/W – Jump if the source variable is 0 or not 0.


cond Code

Condition

True State

EQ

Equal

Z=1

IS

Not Equal

Z=0

CS

Carry Set

C=1

CC

Carry Clear

C=0

HI

Higher [unsigned]

L=1

LS

Lower or Same [unsigned]

L=0

GT

Greater [signed]

N=1

THE

Less or Equal [signed]

N=0

FS

Flag Set

F=1

FC

Flag Clear

F=0

IT

Lower

Z=0 and L=0

HS

Higher or Same

Z=1 or L=1

LT

Less

Z=0 and N=0

GE

Greater or Equal

Z=1 or N=1


  • Logical calculus instructions

    • ANDB/W/D – Performs logical AND operations

    • ORB/W/D - Performs logical OR operations.

    • XORB/W/D - Performs a logical XOR operation.

    • Scond – Stores the judgment result in the target variable


  • Displacement calculation instructions

    • ASHUB/W/D – A shift operation that fills in empty spaces with signed values. Positive values ​​shift left; negative values ​​shift right.

    • LSHB/W/D - Shift operation that fills empty bits with zeros. Positive values ​​shift left; negative values ​​shift right.


  • Bit calculus instructions

    • CBITB/W – Clears the specified bits of the target variable.

    • SBITB/W – Sets the specified bits of the target variable

    • TBIT/B/W – Tests the potential of a specified bit in a temporary register/memory.


  • Processor arithmetic instructions

    • LPR/D – Reads the processor's temporary registers

    • SPR/D – Sets the processor's temporary register

    • CINV[I,D,U] – Clears instructions, data, or non-LOCKed portions from the cache.

    • DI – Disable programmable interruption

    • EI – Enables programmable interrupts

    • EIWAIT – Enables programmable interrupts when the next interrupt occurs.

    • NOP – Do nothing.

    • WAIT – The program pauses execution until an interrupt occurs.


  • Jump and link commands

    • BAL RA,L – Stores the address of the next instruction in RA, then jumps to program L for execution.

    • BR – Unconditional Jump

    • EXCP – Exception Handling

    • Jcond – Jumps to the absolute address if the condition is true.

    • JAL RA,L - Stores the address of the next instruction in RA, then jumps to program L to execute.

    • JUMP - Unconditional Jump

    • RETX – Return from interrupt service routine

    • POPRT – Retrieves the value of a register in the stack.

    • PUSH – Moves the value of a temporary register to the stack.


  • Loading and saving instructions

    • LOADB/W/D – Loads the value of a memory or temporary register.

    • STORB/W/D – Stores the value in memory or a temporary register.

    • LOADM/MP – Loads the value of the memory corresponding to R0/(R1,R0) into temporary registers R2, R3, R4, R5, R8, R9, R10, R11, etc., up to a maximum of 8 temporary registers.

    • STORM/MP - Stores the values ​​of registers [R2, R3, R4, R5, R8, R9, R10, R11] into the memory corresponding to R0/(R1,R0). A maximum of 8 values ​​can be stored.


留言

這個網誌中的熱門文章

EC 所需知識 - SMBUS

EC Required Knowledge - KBC

EC Required Knowledge - LPC