From: Milo Kim Date: Fri, 17 Apr 2015 19:43:11 +0000 (+0900) Subject: Initial commit X-Git-Url: https://git.ti.com/gitweb?p=lasm%2Flp5523_lasm_linux.git;a=commitdiff_plain;h=a5a5bd9871b1c1a11ebadb0f0495d8269a099823 Initial commit --- a5a5bd9871b1c1a11ebadb0f0495d8269a099823 diff --git a/_lasm_cmd_parser.py b/_lasm_cmd_parser.py new file mode 100644 index 0000000..6ee46b8 --- /dev/null +++ b/_lasm_cmd_parser.py @@ -0,0 +1,712 @@ +# +# Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions an +# limitations under the License. +# +# +# LASM Command Parser +# +# Search a command and convert into 16bit code +# Written based on documents below +# - www.ti.com/lit/ds/symlink/lp5523.pdf +# - www.ti.com/lit/an/snva664/snva664.pdf +# + +import _lasm_utils as util + +# Return type +SUCCESS = 0 +FAILURE = CMD_NOT_FOUND = -1 + + +# Display error +# Format: 'function name' 'error message' +def put_error(message): + func_name = util.get_caller_func_name() + util.put_error(func_name, message) + return FAILURE + + +# Segment command is used for program engine selection (1,2,3) +# Save start SRAM address to calculate label offset +def segment(name): + args = name.split() + if len(args) != 1: + put_error('must have one directive') + return FAILURE + + util.add_segment_list(args[0]) + return SUCCESS + + +def mux_map_start(label): + args = label.split() + if len(args) != 1: + put_error('must have one argument') + return FAILURE + + code = util.get_address_of_label(args[0], '') + if code == util.INVALID_ADDR: + return FAILURE + + MUX_MAP_START = 0x9C00 + util.put_code(MUX_MAP_START | code) + return SUCCESS + + +def mux_map_next(val): + util.put_code(0x9D80) + return SUCCESS + + +def mux_map_prev(val): + util.put_code(0x9DC0) + return SUCCESS + + +def mux_ld_next(val): + util.put_code(0x9D81) + return SUCCESS + + +def mux_ld_prev(val): + util.put_code(0x9DC1) + return SUCCESS + + +def mux_ld_addr(label): + args = label.split() + if len(args) != 1: + put_error('must have one argument') + return FAILURE + + code = util.get_address_of_label(args[0], '') + if code == util.INVALID_ADDR: + return FAILURE + + MUX_LD_ADDR = 0x9F00 + util.put_code(MUX_LD_ADDR | code) + return SUCCESS + + +def mux_map_addr(label): + args = label.split() + if len(args) != 1: + put_error('must have one argument') + return FAILURE + + code = util.get_address_of_label(args[0], '') + if code == util.INVALID_ADDR: + return FAILURE + + MUX_MAP_ADDR = 0x9F80 + util.put_code(MUX_MAP_ADDR | code) + return SUCCESS + + +def mux_sel(val): + args = val.split() + if len(args) != 1: + put_error('must have one argument') + return FAILURE + + MAX_LEDS = 9 + GPO = 16 + led = int(args[0]) + if (led < 0 or (led > MAX_LEDS and led is not GPO)): + put_error('invalid argument') + return FAILURE + + MUX_SEL = 0x9D00 + util.put_code(MUX_SEL | led) + return SUCCESS + + +def mux_clr(val): + util.put_code(0x9D00) + return SUCCESS + + +def mux_ld_start(label): + args = label.split() + if len(args) != 1: + put_error('must have one argument') + return FAILURE + + code = util.get_address_of_label(args[0], '') + if code == util.INVALID_ADDR: + return FAILURE + + MUX_LD_START = 0x9E00 + util.put_code(MUX_LD_START | code) + return SUCCESS + + +def mux_ld_end(label): + args = label.split() + if len(args) != 1: + put_error('must have one argument') + return FAILURE + + code = util.get_address_of_label(args[0], '') + if code == util.INVALID_ADDR: + return FAILURE + + MUX_LD_END = 0x9C80 + util.put_code(MUX_LD_END | code) + return SUCCESS + + +def set_pwm(val): + args = val.split() + if len(args) != 1: + put_error('must have one argument') + return FAILURE + + # Format: set_pwm + # set_pwm 'ra' or 'rb' or 'rc' or 'rd' + variables = {'ra': 0, 'rb': 1, 'rc': 2, 'rd': 3} + index_var = variables.get(args[0]) + if index_var is None: + SET_PWM = 0x4000 + code = util.format_number(args[0]) + util.put_code(SET_PWM | code) + return SUCCESS + + SET_PWM = 0x8460 + util.put_code(SET_PWM | index_var) + return SUCCESS + + +def wait(val): + args = val.split() + if len(args) != 1: + put_error('must have one argument') + return FAILURE + + PRESCALE0 = 0.015625 + PRESCALE1 = 0.5 + MASTER_FREQ = 32768 + PRESCALE0_CLK = MASTER_FREQ / 16 + PRESCALE1_CLK = MASTER_FREQ / 512 + MAXCODE = 0x1F + PRESCALE_CODE = 0x40 + + time = float(args[0]) + + if time < 0: + put_error('time should be positive value') + return FAILURE + + if time < PRESCALE0: + code = min(int(round(time * PRESCALE0_CLK, 0)), MAXCODE) + code = code << 1 + elif time < PRESCALE1: + code = min(int(round(time * PRESCALE1_CLK, 0)), MAXCODE) + code = PRESCALE_CODE | (code << 1) + else: + put_error('time should be less than 0.48') + return FAILURE + + util.put_code(code << 8) + return SUCCESS + + +# Format: ramp