1、OSAL代码分析目录AccessCodeSpace.s51 2flashDmaTrigger.s51 2flashErasePage.s51 3OSAL.h 4OSAL.c 7OSAL_CUSTOM_H 18OSAL_Memory.h 19OSAL_Memory.c 21OSAL_Nv.h 27OSAL_Nv.C 28OSAL_PwrMgr.h 45OSAL_PwrMgr.c 46OSAL_Tasks.h 48OSAL_Tasks.c 50OSAL_Timers.h 52OSAL_Timers.c 54ZComDef.h 62AccessCodeSpace.s51 NAME CC2430_RE
2、AD_ANY_CODE_BYTE ; Copyright (c) 2006 by Texas Instruments, Inc. ; All Rights Reserved. Permission to use, reproduce, copy, prepare ; derivative works, modify, distribute, perform, display or sell this ; software and/or its documentation for any purpose is prohibited ; without the express written co
3、nsent of Texas Instruments, Inc.MEMCTR EQU 0xC7 RSEG NEAR_CODE PUBLIC GetCodeByte FUNCTION GetCodeByte, 0203H ; ; Get a byte from code space. ; ; uint8 GetCodeByte(uint32 logical_address) ; ; Input: the logical address is just the offset of the ; byte assuming a contiguous flat address space. ; ; Re
4、turns: Byte read returned in R1 ; ; * ; * Function is a _near_func * ; * ; ; first we have to map the logical address to the linker address. then ; we can populate the MEMCTR register properly. ; ; logical adr linker adr Bank ; 0x00000-0x07FFF - 0x00000-0x07FFF 0 ; 0x08000-0x08FFF - 0x18000-0x1FFFF
5、1 ; 0x10000-0x17FFF - 0x28000-0x2FFFF 2 ; 0x18000-0x1FFFF - 0x38000-0x3FFFF 3 ; ; the logical address is in R5:R4:R3:R2 (MSB-LSB) but R5 should always be 0. ; ; we can tell the bank by shifting the entire address left 1. after that ; the third byte (R4) will contain the bank number (0-3). awkwardnes
6、s ; comes in when setting the DPTR. Once the logical address is 0x7FFF ; the linker address is always begins at 0xb8000 where b is the bank ; number. ; ;GetCodeByte: ; get the bank number MOV A,R4 ; are we past 64K? RL A ; shift the bit (if its there) left MOV B,A ; save the shifted result in B MOV
7、A,R3 ; now we want to shift in the MSB in r3 to complete the bank number ANL A,#0x80 ; mask off the MSB RL A ; shift it into the lsb position. ORL A,B ; OR bit 0 in A with B to complete the bank number SWAP A ; swap to get the bank number into the correct place for MEMCTR MOV B,A ; save it in B ; he
8、res the awkward part. if the bank is 2 we have to add ; 0x80 to R3. XRL A,#0x20 ; A still has the nibble-swapped bank number. if this resault is 0 it was 2. JNZ _notBank2 MOV A,R3 ; its Bank 2. we need to modify R3 for later use in DPH ORL A,#0x80 MOV R3,A ; prepare MEMCTR and DPTR_notBank2: MOV A,M
9、EMCTR ; get current MEMCTR MOV R4,A ; save it ANL A,#0xCF ; mask off bank bits ORL A,B ; OR in the required bank number MOV MEMCTR,A ; save the result to MEMCTR CLR A ; get ready. MOV DPH,R3 MOV DPL,R2 MOVC A,A+DPTR ; get byte MOV R1,A ; move byte to return register MOV MEMCTR,R4 ; restore MEMCTR RE
10、T ENDflashDmaTrigger.s51/* Filename: flashDmaTrigger.s51* Target: cc2430* Author: KJA* Revised: 10/3-2006* Revision: 1.0* Copyright (c) 2006 by Texas Instruments, Inc.* All Rights Reserved. Permission to use, reproduce, copy, prepare* derivative works, modify, distribute, perform, display or sell th
11、is* software and/or its documentation for any purpose is prohibited* without the express written consent of Texas Instruments, Inc.*/;-; This function write 0x02 to FCTL, the reason for doing; this in assembly is that the instruction most be aligned; to 4.; The aligment is done with RSEG RCODE (2);-
12、#include ioCC2430.h MODULE flashDmaTrigger.s51 RSEG RCODE (2) PUBLIC halFlashDmaTrigger FUNCTION halFlashDmaTrigger, 0203HhalFlashDmaTrigger: ORL FCTL, #0x02; RET; END;flashErasePage.s51/* Filename: flashErasePage.s51* Target: cc2430* Author: EFU* Revised: 13/12-2005* Revision: 1.0* Copyright (c) 20
13、06 by Texas Instruments, Inc.* All Rights Reserved. Permission to use, reproduce, copy, prepare* derivative works, modify, distribute, perform, display or sell this* software and/or its documentation for any purpose is prohibited* without the express written consent of Texas Instruments, Inc.*/;-; S
14、ee hal.h for a description of this function.;-#include ioCC2430.h MODULE flashErasePage.s51 RSEG RCODE PUBLIC flashErasePage FUNCTION flashErasePage, 0203H DS 1 flashErasePage: ; R2 (LSB) and R3 (MSB) contains the start address of the buffer from which the program can be run in RAM ; R1 contains the
15、 flash page the data is to be written to ; Make sure that interrupts are off MOV R0, #01; JBC EA, intsOffHere; MOV R0, #00;intsOffHere: ; Storing the initial data pointer select. PUSH DPH; PUSH DPL; PUSH DPH1; PUSH DPL1; PUSH DPS; ; Set DPTR0 = address in XDATA RAM to which the flash write procedure
16、 which is to be copied. MOV A, R3; MOV DPH, A; MOV A, R2; MOV DPL, A; ; Saving the start address of the actual flash write procedure in XDATA RAM. PUSH DPL; PUSH DPH; ; Set DPTR1 = start address of the procedure template in CODE ; This procedure is to be copied to XDATA. MOV DPH1, #HIGH(eraseFlashPr
17、ocStart); MOV DPL1, #LOW(eraseFlashProcStart); ; Use R1 to count loops. MOV R4, #eraseFlashProcEnd - eraseFlashProcStart; ; Copy DPTR1-DPTR0copyLoop: MOV DPS, #1; MOVX A, DPTR; INC DPTR; MOV DPS, #0; MOVX DPTR, A; INC DPTR; DJNZ R4, copyLoop; ; Setting the flash page to write to ; Bits 6:1 of FADDRH
18、 indicates which page to write to. MOV A,R1 RL A MOV FADDRH, A MOV FADDRL, #00H ; Setting the flash write timing according to the clock division factor in CLKCON. MOV A,CLKCON ANL A,#07H MOV R4,A INC R4 MOV A,#054Hrotate: CLR C RRC A DJNZ R4,rotate MOV FWT,A ; Data pointer 0 indicates where the star
19、t of the copied routine in XDATA is located. ; Pointer to start of data to copy is in data pointer 1. MOV DPS, #0; POP DPH; POP DPL; PUSH MEMCTR; MOV MEMCTR, #051H; ; Make the indirect function call LCALL indirCall; POP MEMCTR; ; Using the original data pointer POP DPS; POP DPL1; POP DPH1; POP DPL;
20、POP DPH; MOV A, R0; JZ intsWereOff; SETB EA;intsWereOff: RET; ; Calling the flash write in XDATA RAM. (Pointed to by DPTR0)indirCall: CLR A; JMP A+DPTR;eraseFlashProcStart: ; Erasing the page MOV FCTL, #01HwaitEraseLoop: MOV A, FCTL ANL A,#80H JNZ waitEraseLoopdone: RET;eraseFlashProcEnd: END;OSAL.h
21、#ifndef OSAL_H#define OSAL_H/* Filename: OSAL.h Revised: $Date: 2006-09-29 18:09:20 -0700 (Fri, 29 Sep 2006) $ Revision: $Revision: 12162 $ Description: This API allows the software components in the Z-stack to be written independently of the specifics of the operating system, kernel or tasking envi
22、ronment (including control loops or connect-to-interrupt systems). Notes: Copyright (c) 2006 by Texas Instruments, Inc. All Rights Reserved. Permission to use, reproduce, copy, prepare derivative works, modify, distribute, perform, display or sell this software and/or its documentation for any purpo
23、se is prohibited without the express written consent of Texas Instruments, Inc.*/#ifdef _cplusplusextern C#endif/* * INCLUDES */#include ZComDef.h#include OSAL_Memory.h#include OSAL_Timers.h/* * MACROS */#define osal_offsetof(type, member) (uint16) &(type *) 0)-member)#define OSAL_MSG_NEXT(msg_ptr)
24、(osal_msg_hdr_t *) (msg_ptr) - 1)-next#define OSAL_MSG_Q_INIT(q_ptr) *(q_ptr) = NULL#define OSAL_MSG_Q_EMPTY(q_ptr) (*(q_ptr) = NULL)#define OSAL_MSG_Q_HEAD(q_ptr) (*(q_ptr)/* * CONSTANTS */* Interrupts */#define INTS_ALL 0xFF/* * TYPEDEFS */typedef struct void *next; uint16 len; byte dest_id; osal_
25、msg_hdr_t;typedef struct uint8 event; uint8 status; osal_event_hdr_t;typedef void * osal_msg_q_t;/* * GLOBAL VARIABLES */* * FUNCTIONS */* Message Management */ /* * Task Message Allocation */ extern byte * osal_msg_allocate(uint16 len ); /* * Task Message Deallocation */ extern byte osal_msg_deallo
26、cate( byte *msg_ptr ); /* * Task Messages Count */ extern UINT16 osal_num_msgs( void ); /* * Send a Task Message */ extern byte osal_msg_send( byte destination_task, byte *msg_ptr ); /* * Receive a Task Message */ extern byte *osal_msg_receive( byte task_id ); /* * Enqueue a Task Message */ extern void osal_msg_enqueue( osal_msg_q_t *q_ptr, void *msg_ptr ); /* * Enqueue a Task Message Up to Max */ extern byte osal_msg_enqueue_max( osal_msg_q_t *q_p
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1